create-vite-extra icon indicating copy to clipboard operation
create-vite-extra copied to clipboard

type errors with `deno-react` + `Typescript`

Open scarf005 opened this issue 1 year ago • 13 comments

Issue

image JSX element implicitly has type 'any' because no interface 'JSX.IntrinsicElements' exists. errors are popping OOTB.

this may be related to https://github.com/denoland/deno/issues/9425.

How to reproduce

  1. follow the installation steps.
$ deno run --allow-read --allow-write --allow-env npm:create-vite-extra@latest
✔ Project name: … vite-project
✔ Select a template: › deno-react
✔ Select a variant: › TypeScript

Scaffolding project in /home/scarf/repo/cata/vite-project...

Done. Now run:

  cd vite-project
  deno task dev
  1. enable deno for the workspace. image

System Information

ubuntu 23.04 vscode 1.78.1, with deno extension v3.17.0

scarf005 avatar May 10 '23 05:05 scarf005

There's also a similar issue open in Vite recently without Deno: https://github.com/vitejs/vite/issues/13129. Not sure if it's related. There's also this Deno issue which seems to be the same: https://github.com/denoland/deno/issues/16653. The solution (https://github.com/denoland/deno/issues/16653#issuecomment-1383657630) worked a bit but there's still lingering TS errors.

cc @bartlomieju

bluwy avatar May 12 '23 07:05 bluwy

Hi!

That sounds similar to an issue I had a few days ago. Updating moduleResolution to node (maybe others too) fixed it for me. Updating VS Code was ultimately the solution, which allowed me to roll back changes to moduleResolution back to bundler.

https://github.com/vitejs/vite/issues/13129

rpasechnikov avatar May 12 '23 09:05 rpasechnikov

Thanks for the ping, I'll try to investigate this problem.

bartlomieju avatar May 12 '23 11:05 bartlomieju

as a work-around I've disabled the path to my vite application (running on deno runtime) for deno.enablePaths in .vscode/settings.json.

I've created a deno-react application using npm:create-vite-extra

❯ deno run --allow-read --allow-write --allow-env npm:create-vite-extra@latest

After I renamed src/main.jsx to src/main.tsx I had to change vite.config.mjs to include npm:@types/react

import "npm:[email protected]";
import "npm:[email protected]";
import "npm:[email protected]";

try {
  await import("npm:@types/react");
  await import("npm:@types/react-dom");
} catch (ignore) {}

the imports need to be wrapped into a try-catch because vite/deno complain about import problems, but the important thing is that ./node_modules/@types/react exists for the normal vscode typescript LSP.

Screenshot 2023-07-13 at 16 00 36

tsconfig.json:

{
  "compilerOptions": {
    "moduleResolution": "Bundler",
    "module": "ESNext",
    "target": "ES2022",
    "types": ["node"],
    "lib": ["esnext", "dom"],
    "jsx": "react",
    "allowImportingTsExtensions": true,
    "allowSyntheticDefaultImports": true,
    "noEmit": true
  }
}

hastebrot avatar Jul 13 '23 13:07 hastebrot

I have the same issue, and @hastebrot 's solution didn't work for me. Can someone link me a working example?

Andonvr avatar Jul 11 '24 14:07 Andonvr