-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
JSX import fixes do not support new React JSX Transform (without react import) #41762
Comments
We're still working on exactly figuring out how the new helpful automatic import behavior should interact with TS's framework-agnostic view of JSX |
Any progress made on this yet? |
One workaround I found is: Instead of pressing |
I tried this workaround too, but when I am trying to fix all missing imports, this is a very annoying task. Instead, I |
I have a precommit hook that runs some modified version of that react-jsx codemod as part of lint staged. VERY UGLY solution but that's the best I could do atm. :/ |
Since JSX is no longer apart of a single framework, does this still apply? |
I think this is the same as #41920 |
Any updates on this? |
@cmlenz I gleefully take it back. Updated and tried again with the latest nightly ( |
Adding @zackdotcomputer answer, remember to configure the typescript version in your VSCODE |
As noted in this comment it only works if you have I'm not sure how you'd get around that - ts would need some other way to work out that you're using the new transform. |
So glad to have found this! And thank you @lexanth for the fix. Just to clarify for anyone else stumbling on this thread, you need to a a {
"compilerOptions": {
"baseUrl": "./src",
"checkJs": true,
"jsx": "react-jsx"
}
} You can then use This has been driving me nuts forever, so glad to have found a solution here! |
Maybe it’s also worth mentioning for those who are using Naxt.js that this solution will not work for them . Next.js uses |
Any update for Next.js? Using 4.3.4 and still happening 😭 |
For now, what I did is remove One thing I noticed is this extension recommend the correct imports with CMD + space (or Ctrl + space on Windows) |
@nghiepit does v4.3.5 resolve the issue? |
@nghiepit Are you using next.js? |
@PythonCreator27 Yes. I'm using Next.js {
"compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"module": "esnext",
"jsx": "preserve",
"baseUrl": ".",
"strict": true,
"noEmit": true,
"allowJs": true,
"skipLibCheck": true,
"moduleResolution": "node",
"esModuleInterop": true,
"isolatedModules": true,
"resolveJsonModule": true,
"forceConsistentCasingInFileNames": true
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
"exclude": ["node_modules", ".next"]
} |
|
Any ideas why the TS engine doesn't pick up react if you set jsx to "preserve" or the reasoning behind the decision? The handbook on it says it only affects the emit stage and does not affect type-checking. If I'm working in other configurations and React is at v17, then I shouldn't have to have React imported in each file. If I have my own transpilation system, such as Next, Babel, etc. I'd still like to not have VSCode complaining that React isn't imported into the file. |
Would love a response from the Typescript team on this |
Looking into it 👍 |
what about |
TS Template added by @mjbvz
TypeScript Version: 4.1.2
Search Terms
React 17 introduced a new JSX transform which does not require react to be imported in every file. Support for this was added in TypeScript 4.1. However vscode is still suggesting/requiring the react import before other JSX import fixes are suggested.
Steps to Reproduce:
npx create-react-app my-app --template typescript
cd my-app
code --disable-extensions .
src/Test.tsx
file with contentexport default function Test() { return <App />; }
. It should show a problemCannot find name 'App'.
.import default 'React' from module "react"
before it will suggest the desiredimport default 'App' from module "./App"
.In short, you can't get help with JSX imports without littering your files with unnecessary react imports.
Does this issue occur when all extensions are disabled?: Yes
The text was updated successfully, but these errors were encountered: