Skip to content

Commit bc812c6

Browse files
committed
refactor: narrow onSuccess/onError/onMutate/onSettled callback types to Promise<void> | void in persist-query-client
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.
1 parent 385c501 commit bc812c6

File tree

5 files changed

+12
-12
lines changed

5 files changed

+12
-12
lines changed

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
@@ -20,8 +20,8 @@ import type { PersistQueryClientFeature } from '@tanstack/angular-query-experime
2020

2121
type PersistQueryClientOptions = {
2222
persistOptions: Omit<PersistQueryClientOptionsCore, 'queryClient'>
23-
onSuccess?: () => Promise<unknown> | unknown
24-
onError?: () => Promise<unknown> | unknown
23+
onSuccess?: () => Promise<void> | void
24+
onError?: () => Promise<void> | void
2525
}
2626

2727
/**

packages/query-core/src/mutationCache.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,24 @@ interface MutationCacheConfig {
1616
variables: unknown,
1717
context: unknown,
1818
mutation: Mutation<unknown, unknown, unknown>,
19-
) => Promise<unknown> | unknown
19+
) => Promise<void> | void
2020
onSuccess?: (
2121
data: unknown,
2222
variables: unknown,
2323
context: unknown,
2424
mutation: Mutation<unknown, unknown, unknown>,
25-
) => Promise<unknown> | unknown
25+
) => Promise<void> | void
2626
onMutate?: (
2727
variables: unknown,
2828
mutation: Mutation<unknown, unknown, unknown>,
29-
) => Promise<unknown> | unknown
29+
) => Promise<void> | void
3030
onSettled?: (
3131
data: unknown | undefined,
3232
error: DefaultError | null,
3333
variables: unknown,
3434
context: unknown,
3535
mutation: Mutation<unknown, unknown, unknown>,
36-
) => Promise<unknown> | unknown
36+
) => Promise<void> | void
3737
}
3838

3939
interface NotifyEventMutationAdded extends NotifyEvent {

packages/query-core/src/query.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export interface FetchContext<
6565
TData,
6666
TQueryKey extends QueryKey = QueryKey,
6767
> {
68-
fetchFn: () => unknown | Promise<unknown>
68+
fetchFn: () => Promise<unknown> | unknown
6969
fetchOptions?: FetchOptions
7070
signal: AbortSignal
7171
options: QueryOptions<TQueryFnData, TError, TData, any>

packages/query-core/src/types.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,18 +1105,18 @@ export interface MutationOptions<
11051105
data: TData,
11061106
variables: TVariables,
11071107
context: TContext,
1108-
) => Promise<unknown> | unknown
1108+
) => Promise<void> | void
11091109
onError?: (
11101110
error: TError,
11111111
variables: TVariables,
11121112
context: TContext | undefined,
1113-
) => Promise<unknown> | unknown
1113+
) => Promise<void> | void
11141114
onSettled?: (
11151115
data: TData | undefined,
11161116
error: TError | null,
11171117
variables: TVariables,
11181118
context: TContext | undefined,
1119-
) => Promise<unknown> | unknown
1119+
) => Promise<void> | void
11201120
retry?: RetryValue<TError>
11211121
retryDelay?: RetryDelayValue<TError>
11221122
networkMode?: NetworkMode

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import type { OmitKeyof, QueryClientProviderProps } from '@tanstack/react-query'
1111

1212
export type PersistQueryClientProviderProps = QueryClientProviderProps & {
1313
persistOptions: OmitKeyof<PersistQueryClientOptions, 'queryClient'>
14-
onSuccess?: () => Promise<unknown> | unknown
15-
onError?: () => Promise<unknown> | unknown
14+
onSuccess?: () => Promise<void> | void
15+
onError?: () => Promise<void> | void
1616
}
1717

1818
export const PersistQueryClientProvider = ({

0 commit comments

Comments
 (0)