deno icon indicating copy to clipboard operation
deno copied to clipboard

JSX element implicitly has type 'any' because no interface 'JSX.IntrinsicElements' exists. When using Preact v10.16.0

Open sant123 opened this issue 2 years ago • 12 comments
trafficstars

image

This is my deno.json

{
  "compilerOptions": {
    "jsx": "react-jsx",
    "jsxImportSource": "preact"
  },
  "tasks": {
    "start": "deno run -A --watch=static/,routes/ dev.ts",
    "vpn": "DENO_DEPLOYMENT_ID=\"$(git rev-parse HEAD)\" deno run -A main.ts"
  },
  "imports": {
    "$fresh/": "https://deno.land/x/[email protected]/",
    "preact": "https://esm.sh/[email protected]",
    "preact/": "https://esm.sh/[email protected]/",
    "preact-render-to-string": "https://esm.sh/*[email protected]",
    "@preact/signals": "https://esm.sh/*@preact/[email protected]",
    "@preact/signals-core": "https://esm.sh/@preact/[email protected]"
  }
}

Thanks!

sant123 avatar Jul 18 '23 17:07 sant123

Can you check that the deno vscode plugin is initialized? There is a command for that in the vscode command palette.

marvinhagemeister avatar Jul 18 '23 18:07 marvinhagemeister

Yep it is, in fact this is a project I'm currently running. Changing it to Preact v10.15.1 works good. That's my workaround for now.

sant123 avatar Jul 18 '23 19:07 sant123

Screencast.from.2023-07-18.14-03-35.webm

Solutions

  1. Ctrl/Cmd + Shift + P then choose Reload Window (vscode)
  2. run fresh
deno task start

and reload browser window (deno automatically cache missing dependencies)

afifurrohman-id avatar Jul 20 '23 17:07 afifurrohman-id

I use all latest preact / twind and it's work fine

afifurrohman-id avatar Jul 20 '23 17:07 afifurrohman-id

Really weird @afifurrohman-id. I followed the steps you provided + I added --reload in my task to renew cache but still is showing that warning. image

sant123 avatar Jul 21 '23 15:07 sant123

Alright I think I figured out the issue, but the workaround is a little odd to me:

To replicate the issue:

  • Close any VSCode instance
  • Delete Deno's cache. On Linux rm -r $HOME/.cache/deno
  • Open a Fresh project with VSCode and select any .tsx file

You should see something like this:

image

  • Run deno task start
  • Now restart the Deno language server

image

Now you should be able to see the error above:

image

  • To get rid of this annoying issue, stop the fresh server and run deno check main.ts

image

image

My question is, why using deno check solves the issue? I tried running with both dev.ts and main.ts and did not work.

sant123 avatar Jul 26 '23 17:07 sant123

@sant123 this worked for me. Idk why deno check works either, but it did. I was just using the default fresh template from their "Getting Started", as well. Might be worth fixing...

mct-dev avatar Aug 15 '23 18:08 mct-dev

FWIW For people commenting here: It's not an issue with Fresh but with Deno's LSP. We are aware of the issue but haven't found the root cause yet nor a reliable way to reproduce it. Sometimes I can reproduce it and when I try again it doesn't work anymore. The steps listed earlier in the thread don't work for me to reproduce it.

My guess as to why deno check works is that it may refresh the internal type cache or something.

marvinhagemeister avatar Aug 15 '23 19:08 marvinhagemeister

I'll transfer this upstream to the deno cli repository, since this is not an issue with Fresh.

marvinhagemeister avatar Sep 20 '23 09:09 marvinhagemeister

for me restarting the LSP / vscode didn't do it, but running deno check main.ts and then restarting the LSP did.

guy-borderless avatar Oct 06 '23 10:10 guy-borderless

Follow documentation at https://docs.deno.com/runtime/manual/advanced/jsx_dom/jsx. There are multiple options, the least intrusive seems to be having deno.jsonc with this:

  "compilerOptions": {
    "jsx": "react-jsx",
    "jsxImportSource": "https://esm.sh/[email protected]"
  }

fhucko avatar Oct 06 '23 22:10 fhucko

In my case, I have a core program, and from that I have auxiliary components¹: test, web app, cli app. Initially I worked on the core + cli app + test, then recently I work on the web app with Fresh. At first I separated the project to learn the framework easier. Then I joined them together so that I could debug the core easier. My code works fine when it's in a separate project; all I do is to copy it to the bigger one. Now every component has this problem:

JSX element implicitly has type 'any' because no interface 'JSX.IntrinsicElements' exists.deno-ts(7026)

Reload VS Code doesn't help.

It turns out that VS Code can recognize the deno.json file in the root folder, not the component¹ folder (i.e. ./aux/web/deno.json). The file also have to have at least these line:

  "compilerOptions": {
    "jsx": "react-jsx",
    "jsxImportSource": "preact"
  },
  "imports": {
    "preact/": "https://esm.sh/[email protected]/"
  }

ooker777 avatar Jan 12 '24 06:01 ooker777

deno check main.ts didn't solve the problem for me in my Fresh project.

adamzerner avatar Apr 15 '24 04:04 adamzerner

@adamzerner There was a regression that was fixed recently, try with deno upgrade --canary.

nayeemrmn avatar Apr 15 '24 04:04 nayeemrmn

@nayeemrmn Looks like that did the trick. Thanks.

adamzerner avatar Apr 15 '24 05:04 adamzerner