Skip to content

Commit 2e03a61

Browse files
authored
fix(types): allow returning of any promise in the mutation callbacks (TanStack#2189)
1 parent 9626c1b commit 2e03a61

File tree

3 files changed

+22
-14
lines changed

3 files changed

+22
-14
lines changed

docs/src/pages/reference/useMutation.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,15 @@ mutate(variables, {
4646
- This function will fire before the mutation function is fired and is passed the same variables the mutation function would receive
4747
- Useful to perform optimistic updates to a resource in hopes that the mutation succeeds
4848
- 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.
49-
- `onSuccess: (data: TData, variables: TVariables, context?: TContext) => Promise<void> | void`
49+
- `onSuccess: (data: TData, variables: TVariables, context?: TContext) => Promise<unknown> | void`
5050
- Optional
5151
- This function will fire when the mutation is successful and will be passed the mutation's result.
5252
- If a promise is returned, it will be awaited and resolved before proceeding
53-
- `onError: (err: TError, variables: TVariables, context?: TContext) => Promise<void> | void`
53+
- `onError: (err: TError, variables: TVariables, context?: TContext) => Promise<unknown> | void`
5454
- Optional
5555
- This function will fire if the mutation encounters an error and will be passed the error.
5656
- If a promise is returned, it will be awaited and resolved before proceeding
57-
- `onSettled: (data: TData, error: TError, variables: TVariables, context?: TContext) => Promise<void> | void`
57+
- `onSettled: (data: TData, error: TError, variables: TVariables, context?: TContext) => Promise<unknown> | void`
5858
- Optional
5959
- This function will fire when the mutation is either successfully fetched or encounters an error and be passed either the data or error
6060
- If a promise is returned, it will be awaited and resolved before proceeding

src/core/types.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,13 @@ export interface FetchInfiniteQueryOptions<
225225
TError = unknown,
226226
TData = TQueryFnData,
227227
TQueryKey extends QueryKey = QueryKey
228-
> extends FetchQueryOptions<TQueryFnData, TError, InfiniteData<TData>, TQueryKey> {}
228+
>
229+
extends FetchQueryOptions<
230+
TQueryFnData,
231+
TError,
232+
InfiniteData<TData>,
233+
TQueryKey
234+
> {}
229235

230236
export interface ResultOptions {
231237
throwOnError?: boolean
@@ -474,23 +480,25 @@ export interface MutationOptions<
474480
mutationFn?: MutationFunction<TData, TVariables>
475481
mutationKey?: MutationKey
476482
variables?: TVariables
477-
onMutate?: (variables: TVariables) => Promise<TContext> | Promise<undefined> | TContext | undefined
483+
onMutate?: (
484+
variables: TVariables
485+
) => Promise<TContext> | Promise<undefined> | TContext | undefined
478486
onSuccess?: (
479487
data: TData,
480488
variables: TVariables,
481489
context: TContext
482-
) => Promise<void> | void
490+
) => Promise<unknown> | void
483491
onError?: (
484492
error: TError,
485493
variables: TVariables,
486494
context: TContext | undefined
487-
) => Promise<void> | void
495+
) => Promise<unknown> | void
488496
onSettled?: (
489497
data: TData | undefined,
490498
error: TError | null,
491499
variables: TVariables,
492500
context: TContext | undefined
493-
) => Promise<void> | void
501+
) => Promise<unknown> | void
494502
retry?: RetryValue<TError>
495503
retryDelay?: RetryDelayValue<TError>
496504
_defaulted?: boolean
@@ -515,18 +523,18 @@ export interface MutateOptions<
515523
data: TData,
516524
variables: TVariables,
517525
context: TContext
518-
) => Promise<void> | void
526+
) => Promise<unknown> | void
519527
onError?: (
520528
error: TError,
521529
variables: TVariables,
522530
context: TContext | undefined
523-
) => Promise<void> | void
531+
) => Promise<unknown> | void
524532
onSettled?: (
525533
data: TData | undefined,
526534
error: TError | null,
527535
variables: TVariables,
528536
context: TContext | undefined
529-
) => Promise<void> | void
537+
) => Promise<unknown> | void
530538
}
531539

532540
export type MutateFunction<

src/react/types.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,18 +85,18 @@ export interface UseMutationOptions<
8585
data: TData,
8686
variables: TVariables,
8787
context: TContext | undefined
88-
) => Promise<void> | void
88+
) => Promise<unknown> | void
8989
onError?: (
9090
error: TError,
9191
variables: TVariables,
9292
context: TContext | undefined
93-
) => Promise<void> | void
93+
) => Promise<unknown> | void
9494
onSettled?: (
9595
data: TData | undefined,
9696
error: TError | null,
9797
variables: TVariables,
9898
context: TContext | undefined
99-
) => Promise<void> | void
99+
) => Promise<unknown> | void
100100
retry?: RetryValue<TError>
101101
retryDelay?: RetryDelayValue<TError>
102102
useErrorBoundary?: boolean

0 commit comments

Comments
 (0)