-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
fix: expand callback return types to support Promise<Array<void>> for Promise.all() usage #9241
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
Closed
braden-w
wants to merge
6
commits into
TanStack:main
from
epicenterhq:refactor/narrow-callback-types
Closed
fix: expand callback return types to support Promise<Array<void>> for Promise.all() usage #9241
braden-w
wants to merge
6
commits into
TanStack:main
from
epicenterhq:refactor/narrow-callback-types
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
…to Promise<void> | void Previously, the `onSuccess`, `onError`, `onMutate`, and `onSettled` callbacks were typed as `() => Promise<unknown> | unknown`. While `unknown` is technically valid, it implies that the return value might be used, assigned, or further processed. However, throughout the codebase, these callbacks are invoked solely for their side effects, and their return values are always ignored. Narrowing the type to `Promise<void> | void` makes this intent explicit, clarifies that any return value will be discarded, and prevents misleading type signatures that suggest otherwise. This commit narrows their types to `() => Promise<void> | void`, which more accurately reflects their intended use.
…n-related documentation This commit refines the documentation for mutation-related callbacks (`onSuccess`, `onError`, `onSettled`, and `onMutate`), changing their return types from `Promise<unknown> | unknown` to `Promise<void> | void`.
… Promise.all() usage
…e<Array<void>> for improved handling in onSuccess and onError
View your CI Pipeline Execution ↗ for commit fce255f.
☁️ Nx Cloud last updated this comment at |
This was referenced Jun 3, 2025
Merged
Actually, scratch this PR: we should instead change the return types to just be |
braden-w
added a commit
to epicenterhq/query
that referenced
this pull request
Jun 4, 2025
Replace callback return type unions with unions of complete function signatures to improve type safety and clarity. This change addresses the issues raised in TanStack#9241 and TanStack#9245 by: - Preventing mixed sync/async behavior within single callbacks - Maintaining support for Promise.all() patterns
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
documentation
Improvements or additions to documentation
package: query-core
package: react-query-persist-client
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 expands the callback return types from
Promise<void> | void
tovoid | Promise<void> | Promise<Array<void>>
to address user feedback from #9202.PR #9202 narrowed callback types from
Promise<unknown> | unknown
toPromise<void> | void
to better reflect the intent that callback return values are ignored. However, this change broke existing user code that was using a common pattern of returningPromise.all()
from callbacks.Problem
The change broke code like this:
Since
Promise.all()
returnsPromise<Array<void>>
, this pattern was no longer type-compatible.Solution
This PR adds
Promise<Array<void>>
to the union type, allowing the commonPromise.all()
pattern while maintaining the intent that individual callback return values are ignored (they're all variations ofvoid
).Updated type signature:
Changes Made
MutationOptions
interfaceMutationCacheConfig
interfaceAddresses
Promise.all()
usage pattern in mutation callbacksFixes #9202 (user feedback)