-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
refactor: narrow onSuccess/onError/onMutate/onSettled callback types to Promise<void> | void #9202
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
refactor: narrow onSuccess/onError/onMutate/onSettled callback types to Promise<void> | void #9202
Conversation
View your CI Pipeline Execution ↗ for commit 26a2647.
☁️ Nx Cloud last updated this comment at |
bc812c6
to
bf7af4e
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #9202 +/- ##
===========================================
+ Coverage 45.24% 59.56% +14.32%
===========================================
Files 209 138 -71
Lines 8247 5485 -2762
Branches 1860 1467 -393
===========================================
- Hits 3731 3267 -464
+ Misses 4076 1921 -2155
+ Partials 440 297 -143 🚀 New features to boost your workflow:
|
This commit builds on the changes introduced in [refactor/narrow-callback-types](TanStack#9202) and replaces all instances of `Promise<T> | T` with the new `MaybePromise<T>` helper type. The `MaybePromise` type, originally defined in `@tanstack/query-persist-client-core/src/createPersister.ts`, is now moved to `query-core` for broader, consistent use. - Moves the `MaybePromise` type definition to `query-core`, making it the canonical utility for representing values that may be returned synchronously or as a promise. - Updates all relevant callback signatures (such as `onSuccess`, `onError`, `onMutate`, `onSettled`, and other callbacks) to use `MaybePromise<T>` instead of `Promise<T> | T`. - Updates documentation to reference `MaybePromise<T>` for clarity and consistency. This builds on the direction set by [refactor/narrow-callback-types](TanStack#9202), further improving type readability and maintainability by using a single, expressive type for all maybe-async callback returns.
…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`.
52de5b7
to
26a2647
Compare
This commit builds on the changes introduced in [refactor/narrow-callback-types](TanStack#9202) and replaces all instances of `Promise<T> | T` with the new `MaybePromise<T>` helper type. The `MaybePromise` type, originally defined in `@tanstack/query-persist-client-core/src/createPersister.ts`, is now moved to `query-core` for broader, consistent use. - Moves the `MaybePromise` type definition to `query-core`, making it the canonical utility for representing values that may be returned synchronously or as a promise. - Updates all relevant callback signatures (such as `onSuccess`, `onError`, `onMutate`, `onSettled`, and other callbacks) to use `MaybePromise<T>` instead of `Promise<T> | T`. - Updates documentation to reference `MaybePromise<T>` for clarity and consistency. This builds on the direction set by [refactor/narrow-callback-types](TanStack#9202), further improving type readability and maintainability by using a single, expressive type for all maybe-async callback returns.
@braden-w @TkDodo
And with the following change I am getting the following error: What would you suggest me to do? |
Same issue as @Sagie501 for us. Not trying to start a flood of +1s, but I think it makes sense to clarify that this is a somewhat commonly used pattern, probably impacting many users. |
Changing the callbacks type to |
Previously, the
onSuccess
,onError
,onMutate
, andonSettled
callbacks were typed as() => Promise<unknown> | unknown
. Whileunknown
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 toPromise<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.