-
-
Notifications
You must be signed in to change notification settings - Fork 485
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
💅 React TypeScript issue on The React variable is undeclared
#3998
Comments
Hi! You can explicitly set a global using the |
We did try globals, though that introduces other issues. // biome.json
"javascript": {
"globals": ["React"]
} For instance, in a non-TS .jsx file you can add this without an import. // App.jsx
function App() {
const [count, setCount] = React.useState(0);
} Biome will allow it due to globals, but the app will error during runtime. One other option was just to disable |
Have you suggestions to solve the issue? We could add metadata to globals (if it is a type, a writable flobal, ...). Also, we have a |
I think the I’m also used to just disabling this rule, since it’s kinda redundant if you also use |
I don't have any suggestions unfortunately. But disabling it seems to be ok, since TypeScript will handle undeclared issues on its own in .tsx files. We do run |
This one of the reason |
Thanks @Conaclos, it does help in .js/.jsx files. As we're used to it coming from ESLint. |
It seems that there are more false positives with types than variables. We could add an option to ignore undeclared types. We could allow the option by default and allow the rule by default in Biome 2.0. What do you think? |
That's a good idea. Since types are already checked by TypeScript tsc. |
I am facing same issue. Is there a plan to fix this? |
@marmikdesai please read the whole conversation, because it answers your question |
This would be awesome! |
Actually, I think we should always ignore types in |
Environment information
Rule name
noUndeclaredVariables
Playground link
https://biomejs.dev/playground/?lintRules=all&code=ZgB1AG4AYwB0AGkAbwBuACAATQB5AEEAcABwACgAKQAgAHsACgAgACAAZgB1AG4AYwB0AGkAbwBuACAAaABhAG4AZABsAGUAcgAoAGUAOgAgAFIAZQBhAGMAdAAuAEYAbwByAG0ARQB2AGUAbgB0ACkAIAB7AAoAIAAgACAAIAByAGUAdAB1AHIAbgAgAGUACgAgACAAfQAKAAoAIAAgAHIAZQB0AHUAcgBuACAAKAAKACAAIAAgACAAPABmAG8AcgBtACAAbwBuAFMAdQBiAG0AaQB0AD0AewAoAGUAKQAgAD0APgAgAGgAYQBuAGQAbABlAHIAKABlACkAfQA%2BAAoAIAAgACAAIAA8AC8AZgBvAHIAbQA%2BAAoAIAAgACkACgB9AAoACgBlAHgAcABvAHIAdAAgAHsAIABNAHkAQQBwAHAAIAB9AA%3D%3D
Expected result
Hello, we're migrating a few React 18/TS/EsLint projects into Biome. With React 18 you could use global React Types as
React.JSX.Element
,React.FormEvent
, etc without an import statement.But when we enable
noUndeclaredVariables
in Biome to check for possible bugs, we're getting a false positive onThe React variable is undeclared
.A workaround is to explicitly add an
import type React from 'react'
on every file with React types. But we have hundreds of files that would need this. And it was working before migrating over.Is there a better solution for this issue?
Thanks, and we love Biome!
Code of Conduct
The text was updated successfully, but these errors were encountered: