-
Notifications
You must be signed in to change notification settings - Fork 91
fix(typing): add undefined to FetchData Promise return type #771
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
Conversation
The fetchData function of useClient request return an empty Promise if the hook is unmounted. Typing has been updated to reflect this behavior
|
👷 Deploy request for graphql-hooks-cra pending review. 🔨 Explore the source changes: c9f9647 |
|
can you please create an issue and use this PR to propose a solution for it? |
|
Another solution would be to return a |
|
Can you please cover this change with a test by changing or adding to the code in https://github.com/nearform/graphql-hooks/tree/master/packages/graphql-hooks/test-d? |
|
@csorfab ping :) |
|
@simoneb sorry for the delay! I checked the typing tests with Have you considered the other option, which would be returning a "dummy" object ( |
|
@csorfab Could you please draft an implementation using your suggestion of returning a dummy object? it's certainly more suitable than an undefined return for sure as you mentioned |
|
@tiagoheliob Hi! I've created a new PR with my implementation of the suggestion: #777 |
|
@csorfab Thanks a lot, I'll take a look |
|
I'm closing this as #777 has been merged instead |
The fetchData function of useClientRequest returns an empty Promise if the hook is unmounted. Typing has been updated to reflect this behavior
What does this PR do?
It fixes a typing error that affects useClientRequest's fetchData function, and as a result, useManualQuery and useMutation too. useClientRequest's fetchData function returns an empty (undefined) Promise if called after the component has unmounted, but this is not currently reflected in its typing. Admittedly, this is an edge case behavior, but it's caused my team hard to reproduce bugs, and since the behavior is codified in useClientRequest.test.js:476 ("returns undefined instantly if not mounted"), it seems appropriate that the typing reflect it.
This would be a breaking change for many projects, but I believe that Typescript's usefulness lies exactly in preventing hard-to-reproduce bugs like those caused by this behavior, so I think it's a small price to pay for correctness.
Related issues
Closes #772
Checklist