Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lack of X-TypeScript-Types header for sub modules of react #225

Closed
misogohan opened this issue Dec 11, 2021 · 2 comments
Closed

Lack of X-TypeScript-Types header for sub modules of react #225

misogohan opened this issue Dec 11, 2021 · 2 comments
Labels
bug Something isn't working

Comments

@misogohan
Copy link

misogohan commented Dec 11, 2021

Case

I knew that Deno 1.16 supports new JSX transforms, and have tried it with https://esm.sh/react.

Minimum code:

const App = () => <h1>Hello, world!</h1>;
{
  "compilerOptions": {
    "jsx": "react-jsx",
    "jsxImportSource": "https://esm.sh/react",
    "lib": [ "dom", "deno.ns" ]
  }
}

After running deno run, I got this:

Check file:///home/misogohan/repro/component.tsx
error: TS7026 [ERROR]: JSX element implicitly has type 'any' because no interface 'JSX.IntrinsicElements' exists.
const App = () => <h1>Hello, world!</h1>;
                  ~~~~
    at file:///home/misogohan/repro/component.tsx:1:19

TS7026 [ERROR]: JSX element implicitly has type 'any' because no interface 'JSX.IntrinsicElements' exists.
const App = () => <h1>Hello, world!</h1>;
                                   ~~~~~
    at file:///home/misogohan/repro/component.tsx:1:36

Found 2 errors.

However, I can dispense with these errors when I use https://esm.sh/preact instead of react.

Cause

With the new JSX transforms, TypeScript implicitly looks up https://esm.sh/react/jsx-runtime, but because its response header does not include X-TypeScript-Types, Deno cannot find the type declaration file of it, and TypeScript cannot resolve JSX namespace.

cf. https://esm.sh/preact/jsx-runtime hasX-TypeScript-Types header, and such errors does not occur.

Solution

I confirmed that there is the type declaration at https://cdn.esm.sh/v58/@types/react/jsx-runtime.d.ts. So just to link it, I guess.

Additional info

  • esm.sh version: v58
  • Deno version: 1.16.4
@KyleJune
Copy link

It might be that if url + '/index.d.ts' does not exist, it assumes there isn't a types file for it. I found another module that it was able to add x-typescript-types header for sub modules.
https://esm.sh/@heroicons/react@1.0.5/outline
It's types was
https://esm.sh/@heroicons/react@1.0.5/outline/index.d.ts.

Maybe having it fallback to checking '.d.ts' would be a reasonable solution that would resolve the issue of it not being able to get the types for these react submodules.

@ije ije closed this as completed in b8a0932 Jan 4, 2022
@ije
Copy link
Member

ije commented Jan 4, 2022

now support submodule types from @types
example: https://github.com/alephjs/esm.sh/tree/master/test/deno/react-jsx-runtime

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants