From 016abef780d3544b2247c4aaee76591989d317d6 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Wed, 2 Sep 2020 18:32:22 +0200 Subject: [PATCH] eslint-plugin-react-hooks: fix compatibility with @typescript-eslint/parser@4.0.0+ In addition to `TSTypeQuery`, dependency nodes with a `TSTypeReference` parent need to be ignored as well. Without this fix, generic type variables will be listed as missing dependencies. Example: export function useFoo(): (foo: T) => boolean { return useCallback((foo: T) => false, []); } This will report the following issue: React Hook useCallback has a missing dependency: 'T'. Either include it or remove the dependency array Closes: #19742 --- packages/eslint-plugin-react-hooks/src/ExhaustiveDeps.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/eslint-plugin-react-hooks/src/ExhaustiveDeps.js b/packages/eslint-plugin-react-hooks/src/ExhaustiveDeps.js index 9899abc0c7d49..d80d701c6869b 100644 --- a/packages/eslint-plugin-react-hooks/src/ExhaustiveDeps.js +++ b/packages/eslint-plugin-react-hooks/src/ExhaustiveDeps.js @@ -406,7 +406,10 @@ export default { }); } - if (dependencyNode.parent.type === 'TSTypeQuery') { + if ( + dependencyNode.parent.type === 'TSTypeQuery' || + dependencyNode.parent.type === 'TSTypeReference' + ) { continue; }