-
Notifications
You must be signed in to change notification settings - Fork 48.5k
Bug: react-hooks/exhaustive-deps false positive when function is casted with TypeScript #20750
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
It looks like it is something that would be easy to support, but the question is: why would you do that? |
Heh, a fair question. In my case, I needed it in order to support generics for a hook that helps manage state for asynchronous calls like mutations:
Without the cast, TS doesn't know that the shape of the args object is the same. On the return statement, TS warns:
This remains true even if I make the args a generic type too, so I think the issue is unavoidable. |
@0x24a537r9 TS is correct there. A function that has the same input type & return type as For your particular situation, the type for |
Ahhh. Thanks @Shrugsy! With that hint I was able to fix my types and obviate the cast. That said, I would recommend keeping this issue open, since there will always be cases where folks will have to resort to casts like these, whether due to limitations in TS's expressiveness or (as in this case and I suspect most cases) one's ability to understand the type complexities and specify the types correctly. Sadly, not everyone has access to a @Shrugsy to help them out when the types get complex. |
…ck (facebook#28202) ## Summary Closes facebook#20750 ## How did you test this change? Added a test case
React version: 17.0.1
Steps To Reproduce
Setup eslint with @typescript-eslint/parser as parser
Cast a function passed to
useEffect
Link to code example: https://github.com/0x24a537r9/exhaustive-deps-bug
The current behavior
The following error was reported
The expected behavior
The rule should interpret the function argument correctly and know that it is already inline.
The text was updated successfully, but these errors were encountered: