question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bug: react-hooks/exhaustive-deps reports a TypeScript type via typeof as a dependency

See original GitHub issue

react-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

  1. Have some typed variable declared in the component.
  2. 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:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
RebeccaStevenscommented, Jul 13, 2020

Looks, like it is. Sorry for the dupe.

0reactions
gaearoncommented, Jul 13, 2020

@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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found