Skip to content

Commit

Permalink
eslint-plugin-react-hooks: fix compatibility with @typescript-eslint/…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
neocturne authored Sep 10, 2020
1 parent a08ae9f commit cd75f93
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/eslint-plugin-react-hooks/src/ExhaustiveDeps.js
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,10 @@ export default {
});
}

if (dependencyNode.parent.type === 'TSTypeQuery') {
if (
dependencyNode.parent.type === 'TSTypeQuery' ||
dependencyNode.parent.type === 'TSTypeReference'
) {
continue;
}

Expand Down

0 comments on commit cd75f93

Please sign in to comment.