Bug: react-hooks/exhaustive-deps reports a TypeScript type via typeof as a dependency
See original GitHub issuereact-hooks/exhaustive-deps reports a missing dependency when a variable is used purely for it’s type.
Once the typescript code has been transpiled, that variable will no longer be referenced in that part of the code and thus it’s not a dependency.
React version: react@16.13.1 Eslint Plugin version: eslint-plugin-react-hooks@4.0.7
Steps To Reproduce
- Have some typed variable declared in the component.
- Within a hook callback, refer to that variable’s type via
typeof x
Link to code example: https://codesandbox.io/s/late-sun-rpws4?file=/src/App.tsx
The current behavior
An eslint error such as the following occurs:
react-hooks/exhaustive-deps - "React Hook useEffect has a missing dependency: ..."
The expected behavior
No error should occur.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:5 (4 by maintainers)
Top Results From Across the Web
Documentation - Typeof Type Operator
Using the typeof operator in type contexts. ... type K = boolean. Try. If we try to use ReturnType on a function name,...
Read more >typescript-cheatsheet - GitHub Pages
A set of TypeScript related notes used for quick reference. The cheatsheet contains references to types, classes, decorators, and many other TypeScript ......
Read more >React + Redux Toolkit: JWT Authentication and Authorization
RTK Query is a server state management library for ReactJs. This article will teach you how to implement JWT Authentication and ...
Read more >The React.ReactNode type is a black hole - Changelog
But then the real puzzle started: Isn't this type of bug exactly what using TypeScript and types is supposed to prevent?
Read more >ReactJS and Typescript : refers to a value, but is being ...
myclass'; let abc: InstanceType<typeof MyClass>; // no error // the rest... The typeof operator gets you the class constructor type for a ...
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
Looks, like it is. Sorry for the dupe.
@delca85 fixed this in #19316. If you find other similar issues, please report them too! Thanks.
eslint-plugin-react-hooks@4.0.8
should have the fix.