From cd75f93c03a15d00f0f82f52587f110d6fba7216 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Thu, 10 Sep 2020 12:30:18 +0200 Subject: [PATCH] eslint-plugin-react-hooks: fix compatibility with @typescript-eslint/parser@4.0.0+ (#19751) 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; }