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

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:7
  • Comments:10

github_iconTop GitHub Comments

2reactions
eps1loncommented, 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

1reaction
mschl0sscommented, Dec 11, 2020

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
Read more comments on GitHub >

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

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