-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
refactor: standardize use of MaybePromise<T> in place of Promise<T> | T #9203
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
Open
braden-w
wants to merge
6
commits into
TanStack:main
Choose a base branch
from
EpicenterHQ:refactor/maybe-promise
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+60
−39
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
View your CI Pipeline Execution ↗ for commit 4c22b57.
☁️ Nx Cloud last updated this comment at |
…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`.
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.
3c261c3
to
b5ccf9a
Compare
1804906
to
7b88f66
Compare
This commit continues the standardization of using the `MaybePromise<T>` type across the codebase, updating the callback signatures for `retryer.ts`, `types.ts`, `createPersister.ts`, `PersistQueryClientProvider.svelte`, and `query.ts.`
7b88f66
to
c50170c
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #9203 +/- ##
===========================================
+ 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 modifies the type of `promiseOrValue` in `retryer.ts` from `any` to `MaybePromise<TData>`, aligning with the ongoing effort to standardize the use of `MaybePromise<T>` across the codebase.
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-async-storage-persister
package: query-core
package: query-persist-client-core
package: react-query-persist-client
package: svelte-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 commit builds on the changes introduced in refactor/narrow-callback-types and replaces all instances of
Promise<T> | T
with the newMaybePromise<T>
helper type. TheMaybePromise
type, originally defined in@tanstack/query-persist-client-core/src/createPersister.ts
, is now moved toquery-core
for broader, consistent use.MaybePromise
type definition toquery-core
, making it the canonical utility for representing values that may be returned synchronously or as a promise.onSuccess
,onError
,onMutate
,onSettled
, and other callbacks) to useMaybePromise<T>
instead ofPromise<T> | T
.MaybePromise<T>
for clarity and consistency.This builds on the direction set by refactor/narrow-callback-types, further improving type readability and maintainability by using a single, expressive type for all maybe-async callback returns.