Bug: react-hooks/exhaustive-deps false positive on TypeScript generic type variable
See original GitHub issueReact version: 16.13.1
Steps To Reproduce
- Use type generics in a useEffect.
Code example:
function useBug<T>(): void {
useEffect(() => {
let bug: T;
}, []); // <-- ESLint error: React Hook useEffect has a missing dependency: 'T'.
}
The current behavior
Dependency array throws ESLint error.
React Hook useEffect has a missing dependency: 'T'. Either include it or remove the dependency array react-hooks/exhaustive-deps
The expected behavior
No missing dependencies reported.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:7
- Comments:10
Top Results From Across the Web
Documentation - Generics - TypeScript
This allows us to use our generic type variable Type as part of the types we're working with, rather than the whole type,...
Read more >Typescript. Wrong generic parameter constraint in conditional ...
You just need to check whether or not the inferred Rest is constrained by the extra type: type Last<TProps extends PropertyKey[]> = TProps ......
Read more >generic-type-guard - npm
A PartialTypeGuard is a type guard which given a value of type T can prove it is actually the specialised type U ....
Read more >How To Use Generics in TypeScript - DigitalOcean
Generics are a fundamental feature of statically-typed languages, allowing developers to pass types as parameters to a type, function, ...
Read more >Typescript Generics Explained - Ross Bulat - Medium
Now we have an identities() function that supports two generic types, with the addition of the U type variable — but the return...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Fairly certain this error was fixed at some point. Make sure to use the latest version of
eslint-plugin-react-hooks
and@typescript-eslint/parser
. If the error persists please let me know and share the result ofnpx envinfo --npmPackages '{eslint,eslint-plugin-react-hooks,@typescript-eslint/*}' --showNotFound --fullTree
Results: