To use @types/react, do I have to prefix all my React imports with // @deno-types ?
Re: https://docs.deno.com/runtime/fundamentals/node/#importing-types
React does not ship with types, and they have to be installed at npm:@types/react.
The documentation says types have to be imported like so:
Surely I don't have to actually prefix all React imports with @deno-types? It's a lot of imports across many files.
Is there a
deno.json
solution?
What if I were to upgrade react, do I have to do a search and replace across the codebase to update the types too?
Any help is appreciated.Deno
Node and npm support
In-depth documentation, guides, and reference materials for building secure, high-performance JavaScript and TypeScript applications with Deno
5 Replies
It looks like Typescript has
compilerOptions.types
to automatically resolve @types
packages. Maybe Deno could use the same feature? https://www.typescriptlang.org/tsconfig/#typesTSConfig Reference - Docs on every TSConfig option
From allowJs to useDefineForClassFields the TSConfig reference includes information about all of the active compiler flags setting up a TypeScript project.
Looks like there is an option you can add into deno.json... https://docs.deno.com/runtime/reference/jsx/#jsximportsourcetypes
Deno
JSX
In-depth documentation, guides, and reference materials for building secure, high-performance JavaScript and TypeScript applications with Deno
i belive if you add
npm:@types/react
to the compilerOptions.types array it should type react imports
no it does not it seems...i belive currently we need to specify the deno-types comment https://github.com/denoland/deno/issues/27062
GitHub
deno check
ignores compilerOptions.types
in deno.json
· Issue...Version: Deno 2.1.1 In my deno.json, I have compilerOptions and imports defined like so: { "compilerOptions": { "types": ["@testing-library/jest-dom"] }, "imports...