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<T>(): (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
Matthias Schiffer committed
Sep 10, 2020 at 12:30 UTC
cd75f93c03a15d00f0f82f52587f110d6fba7216
1 file changed
+4
-1
packages/eslint-plugin-react-hooks/src/ExhaustiveDeps.js
+4
-1
@@ -406,7 +406,10 @@ export default {
406
});
407
}
408
409
- if (dependencyNode.parent.type === 'TSTypeQuery') {
409
+ if (
410
+ dependencyNode.parent.type === 'TSTypeQuery' ||
411
+ dependencyNode.parent.type === 'TSTypeReference'
412
+ ) {
413
continue;
414
}
415