deno icon indicating copy to clipboard operation
deno copied to clipboard

`deno check` appears to require `@jsxImportSource` pragma with `"jsx": "react-jsx"` in configuration

Open cscheid opened this issue 2 years ago • 2 comments

I've tested this on v1.21.2 and v1.22.0, both on macOS. Minimal example. Create these files an empty directory:

$ cat compile.jsonc
{
  "compilerOptions": {
    "allowJs": true,
    "lib": ["DOM", "ES2020"],
    "strict": true,
    "jsx": "react-jsx",
    "jsxImportSource": "foo"
  }
}
$ cat im.json
{ "imports": { "foo/jsx-runtime": "./jsx-runtime.ts" } }
$ cat test.tsx
/** @jsxImportSource foo */
export const makeParagraph = () => <p>A paragraph!</p>;
$ cat test2.tsx
export const makeParagraph = () => <p>A paragraph!</p>;
$ cat jsx-runtime.ts
export namespace JSX {
  export type IntrinsicElements = { [key: string]: unknown };
}

This call succeeds:

$ deno check test.tsx -c compile.jsonc --importmap=im.json

But this one doesn't:

$ deno check test2.tsx -c compile.jsonc --importmap=im.json
Check file:///Users/cscheid/Desktop/daily-log/2022/05/25/tsx-deno/test2.tsx
error: TS7026 [ERROR]: JSX element implicitly has type 'any' because no interface 'JSX.IntrinsicElements' exists.
export const makeParagraph = () => <p>A paragraph!</p>;
                                   ~~~
    at file:///Users/cscheid/Desktop/daily-log/2022/05/25/tsx-deno/test2.tsx:1:36

TS7026 [ERROR]: JSX element implicitly has type 'any' because no interface 'JSX.IntrinsicElements' exists.
export const makeParagraph = () => <p>A paragraph!</p>;
                                                  ~~~~
    at file:///Users/cscheid/Desktop/daily-log/2022/05/25/tsx-deno/test2.tsx:1:51

Found 2 errors.

It seems that jsxImportSource is not getting honored by some part of the code, even though deno check itself fails if I don't add jsImportSource to compile.jsonc.

Strangely, if I use a "bad" value in either of those two fields (say, replacing foo with bar in either the .jsonc or the pragma), deno check fails.

cscheid avatar May 25 '22 21:05 cscheid

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jul 30 '22 15:07 stale[bot]

Hi there, and I apologize if this is out-of-etiquette for the repo. I was just wondering if there are plans to address this in future deno versions.

cscheid avatar Jul 30 '22 15:07 cscheid

Fixed by #15561

lucacasonato avatar Aug 24 '22 22:08 lucacasonato

Still needs a test, so reopening

lucacasonato avatar Aug 24 '22 22:08 lucacasonato