-
-
Notifications
You must be signed in to change notification settings - Fork 470
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
Fix invalid data check in query/mutation fn #1975
Conversation
🦋 Changeset detectedLatest commit: 204d5fd The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, could you please provide a test case as well as a patch commit?
After working on tests it got me thinking - should we even check if data is undefined? Because the problem is
I would suggest doing this with a comment that we can safely return undefined since react-query itself will throw an error if (error) {
throw error;
}
if (data === undefined) {
return data as never;
} upd: its a bit complicated with mutationFn tho since undefined is actually allowed as a return value there 🫠 |
I do not exactly remember why we checked for that data in the first place. But maybe yes we could just remove this check as we need to handle responses with no content anyway (see #1973 (comment)). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm ok with the implementation, thanks for the work. Before we merge can you just double check that we cant return undefined because of tanstack query and not because our types are wrong?
And take the opportunity to add your github in the contributors list
throw error; | ||
} | ||
return data; | ||
|
||
return data as Exclude<typeof data, undefined>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't matter since the type is dictated by return type of createClient
anyway, its not inferred from here - just checked that what we return is valid
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me! Good series of tests as well, thanks for taking the time.
Changes
Closes #1973
How to Review
Checklist
docs/
updated (if necessary)pnpm run update:examples
run (only applicable for openapi-typescript)