-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
11
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.
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 c3e3026.
☁️ 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.37% 59.68% +14.31%
===========================================
Files 207 136 -71
Lines 8276 5514 -2762
Branches 1863 1486 -377
===========================================
- Hits 3755 3291 -464
+ Misses 4080 1925 -2155
+ Partials 441 298 -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.
ah, this conflicts now, even tough it was build on top of your other PR. |
…back return types - Convert remaining T | Promise<T> patterns to MaybePromise<T> in streamedQuery and mutation options - Update mutation callback return types from MaybePromise<void> to MaybePromise<unknown> to mirror TanStack#9251
…accordingly - Changed return types of onSuccess, onError, onSettled, and onMutate callbacks from MaybePromise<void> to MaybePromise<unknown> in multiple files, including documentation and TypeScript definitions. - This change aligns with the ongoing migration to a more flexible promise handling approach. - Reduces total changes against main (some extraneous changes needed to be undone after previous merge)
acab8e7
to
1e98a65
Compare
c490e41
to
177bbbe
Compare
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: 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.