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

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

Closed
RebeccaStevens opened this issue Jul 12, 2020 · 5 comments

Comments

@RebeccaStevens
Copy link

RebeccaStevens commented Jul 12, 2020

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: [email protected]
Eslint Plugin version: [email protected]

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.

@RebeccaStevens RebeccaStevens added the Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug label Jul 12, 2020
@rickhanlonii rickhanlonii added Component: ESLint Rules Component: Hooks good first issue and removed Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug labels Jul 13, 2020
@rickhanlonii
Copy link
Member

Oh nice find @RebeccaStevens, confirmed. Any interest in working on a PR?

@rickhanlonii
Copy link
Member

rickhanlonii commented Jul 13, 2020

Actually this may be a dupe of #18828.

And the related PR #19316 may fix it already, will check with the PR author.

@RebeccaStevens
Copy link
Author

Looks, like it is. Sorry for the dupe.

@rickhanlonii
Copy link
Member

No worry! Let's keep this open in case it's slightly different and to make sure we add a test case for this specific example 👍

@gaearon
Copy link
Collaborator

gaearon commented Jul 13, 2020

@delca85 fixed this in #19316. If you find other similar issues, please report them too! Thanks.

[email protected] should have the fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants