-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
test: add callback return type tests for mutation callbacks #9252
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
Merged
TkDodo
merged 5 commits into
TanStack:main
from
epicenterhq:test/add-callback-return-type-tests-for-mutation-callbacks
Jun 5, 2025
Merged
test: add callback return type tests for mutation callbacks #9252
TkDodo
merged 5 commits into
TanStack:main
from
epicenterhq:test/add-callback-return-type-tests-for-mutation-callbacks
Jun 5, 2025
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…callback types to Promise<void> | void (TanStack#9202)" This reverts commit 982f6ca.
Adds test coverage for mutation callback return types, inspired by the discussions and [TkDodo's comment](TanStack#9245 (comment) ) in TanStack#9245 and the original Promise.all() edge case identified in TanStack#9202. The original PR TanStack#9202 narrowed callback return types from `Promise<unknown> | unknown` to `Promise<void> | void`, but this broke common patterns like: ```ts onSuccess: (data) => Promise.all([ invalidateQueries(), trackAnalytics(), ]) ``` As noted in [the original discussion](TanStack#9202 (comment)), this `Promise.all()` pattern was a legitimate use case that many users relied on. These tests ensure we support all the callback patterns that users expect: ✅ **Sync patterns**: Implicit void, explicit void, non-void returns ✅ **Async patterns**: Async functions, Promise.resolve(), Promise<T> returns ✅ **Promise.all() patterns**: The original breaking case from TanStack#9202 ✅ **Promise.allSettled() patterns**: Additional parallel operation support ✅ **Mixed patterns**: Different callback types in same mutation ✅ **Error handling**: All patterns work in error scenarios ✅ **Return value isolation**: Callback returns don't affect mutation result
View your CI Pipeline Execution ↗ for commit 53fc0db.
☁️ Nx Cloud last updated this comment at |
…leanup verification
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #9252 +/- ##
===========================================
+ Coverage 45.37% 59.68% +14.31%
===========================================
Files 207 136 -71
Lines 8276 5514 -2762
Branches 1865 1485 -380
===========================================
- Hits 3755 3291 -464
+ Misses 4080 1925 -2155
+ Partials 441 298 -143 🚀 New features to boost your workflow:
|
TkDodo
approved these changes
Jun 5, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR builds on #9251 and adds test coverage for mutation callback return types, inspired by the discussions and TkDodo's comment in #9245 and the original Promise.all() edge case identified in #9202.
The original PR #9202 narrowed callback return types from
Promise<unknown> | unknown
to
Promise<void> | void
, but this broke common patterns like:As noted in the original discussion,
this
Promise.all()
pattern was a legitimate use case that many users relied on.These tests ensure we support all the callback patterns that users expect:
Shoutouts
void
#9245 about balancing type safety with developer experiencePromise.all()
patternThese tests ensure we maintain backward compatibility while providing clear intent about callback usage patterns.