Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Types incorrectly identified as missing dependencies for [email protected] with @typescript-eslint/[email protected] #19742

Closed
ifiokjr opened this issue Sep 1, 2020 · 6 comments · Fixed by #19751
Labels
Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug

Comments

@ifiokjr
Copy link

ifiokjr commented Sep 1, 2020

React version: 16.13.1 (although this is related to the eslint plugin).

Steps To Reproduce

  1. Install [email protected] with @typescript-eslint/[email protected] in a TypeScript project.
  2. Within your hook define a type, or cast a value to a certain type`
    const actions = useMemo(
    	() => bindActionCreators(MultishiftActions, dispatch) as Partial<Item>,
    	[dispatch],
    );
  3. eslint-plugin-react-hooks responds with this error React Hook useMemo has a missing dependency: Item. Either include it or remove the dependency array.

Link to code example: remirror/remirror/pull/619

  • Checkout the remirror codebase
     git clone https://github.com/remirror/remirror
     git checkout typedoc
  • Install the dependencies with pnpm. To setup pnpm run npm i -g pnpm.
  • Run the command pnpm run lint:es to lint the codebase.

The current behavior

Types are identified as missing dependencies within a hook and CI fails.

The expected behavior

Types shouldn't be identified as missing dependencies.

@ifiokjr ifiokjr added the Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug label Sep 1, 2020
@neocturne
Copy link
Contributor

This issue was introduced with @typescript-eslint/parser 4.0.0.

@ifiokjr
Copy link
Author

ifiokjr commented Sep 2, 2020

Thanks for the information. I'll update the details. Should I move this to the typescript-eslint repo?

@ifiokjr ifiokjr changed the title Bug: Types incorrectly identified as missing dependencies for [email protected] with [email protected] Bug: Types incorrectly identified as missing dependencies for [email protected] with @typescript-eslint/[email protected] Sep 2, 2020
@neocturne
Copy link
Contributor

Thanks for the information. I'll update the details. Should I move this to the typescript-eslint repo?

No, I already asked there, it will need to be fixed up in the react plugin. I have a fix locally, will send a PR in a moment.

neocturne added a commit to neocturne/react that referenced this issue Sep 2, 2020
[email protected]+

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: facebook#19742
gaearon pushed a commit that referenced this issue Sep 10, 2020
[email protected]+ (#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
@gaearon
Copy link
Collaborator

gaearon commented Sep 10, 2020

[email protected] should have the fix.

@alecmolloy
Copy link

thanks!

koto pushed a commit to koto/react that referenced this issue Jun 15, 2021
[email protected]+ (facebook#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: facebook#19742
@dgattey
Copy link

dgattey commented Apr 29, 2022

I'm on [email protected] and I'm still seeing this when using a generic value inside a callback. Why might that be? I'm getting React Hook useCallback has a missing dependency: 'Value'. Either include it or remove the dependency array react-hooks/exhaustive-deps with const data: Value = JSON.parse(decompressedValue); as the line that causes the error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug
Projects
None yet
5 participants