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 false positive on TypeScript generic type variable #20395

Closed
mschl0ss opened this issue Dec 7, 2020 · 10 comments

Comments

@mschl0ss
Copy link

mschl0ss commented Dec 7, 2020

React version: 16.13.1

Steps To Reproduce

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

@mschl0ss mschl0ss added the Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug label Dec 7, 2020
@sweetliquid
Copy link
Contributor

Can I take this?

@sweetliquid
Copy link
Contributor

@danielmiladinov

@eps1lon
Copy link
Collaborator

eps1lon commented Dec 11, 2020

@mschl0ss We can't reproduce the reported bug with our versions of @typescript-eslint/parser and eslint-plugin-react-hooks (#20432 adds a passing test that replicates your report). Could you run npx envinfo --npmPackages '{eslint,eslint-plugin-react-hooks,@typescript-eslint/*}' --showNotFound and report back with the result?

@eps1lon eps1lon added Resolution: Needs More Information and removed Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug labels Dec 11, 2020
@sweetliquid
Copy link
Contributor

I built a sandbox to reproduce this problem:

image

Edit facebook/react/issues/20395

@mschl0ss
Copy link
Author

mschl0ss commented Dec 11, 2020

@eps1lon Running that command produced this result:

npx: installed 1 in 3.21s

After running that command I do not see the bug anymore, so I guess that did fix it. Can you explain to me what the command did? Also, why is @sweetliquid seeing the error in his sandbox?

@eps1lon
Copy link
Collaborator

eps1lon commented Dec 11, 2020

I built a sandbox to reproduce this problem:

codesandbox might use outdated dependencies which we can't fix. If I download the codesandbox and install it I get no lint errors which hints at outdated dependencies in codesandbox.

Running that command produced this result:

It should've actually printed something more but I forgot to add an important flag: --fullTree. Could you run npx envinfo --npmPackages '{eslint,eslint-plugin-react-hooks,@typescript-eslint/*}' --showNotFound --fullTree and post the results?

@mschl0ss
Copy link
Author

Results:

npx: installed 1 in 1.494s

  npmPackages:
    @typescript-eslint/eslint-plugin:  4.9.0
    @typescript-eslint/experimental-utils:  4.9.0
    @typescript-eslint/parser:  4.9.0
    @typescript-eslint/scope-manager:  4.9.0
    @typescript-eslint/types:  4.9.0
    @typescript-eslint/typescript-estree:  4.9.0
    @typescript-eslint/visitor-keys:  4.9.0
    eslint:  7.14.0
    eslint-plugin-react-hooks:  4.2.0

@mschl0ss
Copy link
Author

The bug seems to have gone away. I worry that I'm giving you the false impression that the bug is being reproduced with the versions reported above.

@eps1lon
Copy link
Collaborator

eps1lon commented Dec 11, 2020

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 of npx envinfo --npmPackages '{eslint,eslint-plugin-react-hooks,@typescript-eslint/*}' --showNotFound --fullTree

@ecraig12345
Copy link

I hit this too, and it went away after deleting old eslint caches. Something to try if anyone else happens onto this issue.

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

5 participants