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

Make React import fix not block component import fix #50307

Merged

Conversation

andrewbranch
Copy link
Member

“Fixes” #50192

There’s been a lot of confusion lately about whether an import of React is needed in JSX files under different JSX compilers, and how to configure TypeScript to recognize that requirement or lack thereof. Historically, if TypeScript thought that a React import was needed, auto-imports would only offer to import React on JSX opening tags, even if the local component name also needed to be imported.

Before:

(<Component />);
// Errors: Cannot find name 'Component', Cannot find name 'React'
// Fixes: Add import from "react"

After:

(<Component />);
// Errors: Cannot find name 'Component', Cannot find name 'React'
// Fixes: Add import from "./Component", Add import from "react"

Users should still configure TS to get rid of that error if it doesn’t apply to their build system, but hopefully making both auto-imports available will make the misconfiguration a bit less painful, especially for plain-JS VS Code users who are just getting default settings and don’t know where they’re coming from.

@typescript-bot typescript-bot added Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug labels Aug 15, 2022
@andrewbranch andrewbranch merged commit bc52ff6 into microsoft:main Aug 15, 2022
@andrewbranch andrewbranch deleted the react-import-fix-non-blocking branch August 15, 2022 20:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants