Skip to content

Commit 1e98a65

Browse files
committed
chore: restore export of MaybePromise from query-core, update docs 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)
1 parent cdcaad4 commit 1e98a65

File tree

6 files changed

+16
-15
lines changed

6 files changed

+16
-15
lines changed

docs/framework/react/plugins/persistQueryClient.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,12 +214,12 @@ ReactDOM.createRoot(rootElement).render(
214214

215215
- `persistOptions: PersistQueryClientOptions`
216216
- all [options](#options) you can pass to [persistQueryClient](#persistqueryclient) minus the QueryClient itself
217-
- `onSuccess?: () => MaybePromise<void>`
217+
- `onSuccess?: () => MaybePromise<unknown>`
218218
- optional
219219
- will be called when the initial restore is finished
220220
- can be used to [resumePausedMutations](../../../../reference/QueryClient.md#queryclientresumepausedmutations)
221221
- if a Promise is returned, it will be awaited; restoring is seen as ongoing until then
222-
- `onError?: () => MaybePromise<void>`
222+
- `onError?: () => MaybePromise<unknown>`
223223
- optional
224224
- will be called when an error is thrown during restoration
225225
- if a Promise is returned, it will be awaited

docs/framework/react/reference/useMutation.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,15 @@ mutate(variables, {
6868
- This function will fire before the mutation function is fired and is passed the same variables the mutation function would receive
6969
- Useful to perform optimistic updates to a resource in hopes that the mutation succeeds
7070
- The value returned from this function will be passed to both the `onError` and `onSettled` functions in the event of a mutation failure and can be useful for rolling back optimistic updates.
71-
- `onSuccess: (data: TData, variables: TVariables, context: TContext) => MaybePromise<void>`
71+
- `onSuccess: (data: TData, variables: TVariables, context: TContext) => MaybePromise<unknown>`
7272
- Optional
7373
- This function will fire when the mutation is successful and will be passed the mutation's result.
7474
- If a promise is returned, it will be awaited and resolved before proceeding
75-
- `onError: (err: TError, variables: TVariables, context?: TContext) => MaybePromise<void>`
75+
- `onError: (err: TError, variables: TVariables, context?: TContext) => MaybePromise<unknown>`
7676
- Optional
7777
- This function will fire if the mutation encounters an error and will be passed the error.
7878
- If a promise is returned, it will be awaited and resolved before proceeding
79-
- `onSettled: (data: TData, error: TError, variables: TVariables, context?: TContext) => MaybePromise<void>`
79+
- `onSettled: (data: TData, error: TError, variables: TVariables, context?: TContext) => MaybePromise<unknown>`
8080
- Optional
8181
- This function will fire when the mutation is either successfully fetched or encounters an error and be passed either the data or error
8282
- If a promise is returned, it will be awaited and resolved before proceeding

docs/reference/MutationCache.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,19 @@ Its available methods are:
2828

2929
**Options**
3030

31-
- `onError?: (error: unknown, variables: unknown, context: unknown, mutation: Mutation) => MaybePromise<void>`
31+
- `onError?: (error: unknown, variables: unknown, context: unknown, mutation: Mutation) => MaybePromise<unknown>`
3232
- Optional
3333
- This function will be called if some mutation encounters an error.
3434
- If you return a Promise from it, it will be awaited
35-
- `onSuccess?: (data: unknown, variables: unknown, context: unknown, mutation: Mutation) => MaybePromise<void>`
35+
- `onSuccess?: (data: unknown, variables: unknown, context: unknown, mutation: Mutation) => MaybePromise<unknown>`
3636
- Optional
3737
- This function will be called if some mutation is successful.
3838
- If you return a Promise from it, it will be awaited
39-
- `onSettled?: (data: unknown | undefined, error: unknown | null, variables: unknown, context: unknown, mutation: Mutation) => MaybePromise<void>`
39+
- `onSettled?: (data: unknown | undefined, error: unknown | null, variables: unknown, context: unknown, mutation: Mutation) => MaybePromise<unknown>`
4040
- Optional
4141
- This function will be called if some mutation is settled (either successful or errored).
4242
- If you return a Promise from it, it will be awaited
43-
- `onMutate?: (variables: unknown, mutation: Mutation) => MaybePromise<void>`
43+
- `onMutate?: (variables: unknown, mutation: Mutation) => MaybePromise<unknown>`
4444
- Optional
4545
- This function will be called before some mutation executes.
4646
- If you return a Promise from it, it will be awaited

packages/angular-query-persist-client/src/with-persist-query-client.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ import type {
2323

2424
type PersistQueryClientOptions = {
2525
persistOptions: Omit<PersistQueryClientOptionsCore, 'queryClient'>
26-
onSuccess?: () => MaybePromise<void>
27-
onError?: () => MaybePromise<void>
26+
onSuccess?: () => MaybePromise<unknown>
27+
onError?: () => MaybePromise<unknown>
2828
}
2929

3030
/**

packages/query-async-storage-persister/src/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { asyncThrottle } from './asyncThrottle'
22
import { noop } from './utils'
33
import type {
44
AsyncStorage,
5+
MaybePromise,
56
PersistedClient,
67
Persister,
78
Promisable,
@@ -28,12 +29,12 @@ interface CreateAsyncStoragePersisterOptions {
2829
* How to serialize the data to storage.
2930
* @default `JSON.stringify`
3031
*/
31-
serialize?: (client: PersistedClient) => Promisable<string>
32+
serialize?: (client: PersistedClient) => MaybePromise<string>
3233
/**
3334
* How to deserialize the data from storage.
3435
* @default `JSON.parse`
3536
*/
36-
deserialize?: (cachedString: string) => Promisable<PersistedClient>
37+
deserialize?: (cachedString: string) => MaybePromise<PersistedClient>
3738

3839
retry?: AsyncPersistRetryer
3940
}

packages/react-query-persist-client/src/PersistQueryClientProvider.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ import type {
1515

1616
export type PersistQueryClientProviderProps = QueryClientProviderProps & {
1717
persistOptions: OmitKeyof<PersistQueryClientOptions, 'queryClient'>
18-
onSuccess?: () => MaybePromise<void>
19-
onError?: () => MaybePromise<void>
18+
onSuccess?: () => MaybePromise<unknown>
19+
onError?: () => MaybePromise<unknown>
2020
}
2121

2222
export const PersistQueryClientProvider = ({

0 commit comments

Comments
 (0)