Skip to content

Commit f2137dc

Browse files
authored
fix (types): Prefer ReadonlyArray for query keys (#1854)
* Prefer ReadonlyArray for Since keys are treated as readonly anway, this allows users to use `as const` without nasty surprises. * Fix type error * Prefer readonly X[] over ReadonlyArray<X>
1 parent 23846f5 commit f2137dc

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/core/types.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { QueryBehavior } from './query'
33
import type { RetryValue, RetryDelayValue } from './retryer'
44
import type { QueryFilters } from './utils'
55

6-
export type QueryKey = string | unknown[]
6+
export type QueryKey = string | readonly unknown[]
77

88
export type QueryFunction<T = unknown> = (
99
context: QueryFunctionContext<any>
@@ -448,7 +448,7 @@ export type InfiniteQueryObserverResult<TData = unknown, TError = unknown> =
448448
| InfiniteQueryObserverRefetchErrorResult<TData, TError>
449449
| InfiniteQueryObserverSuccessResult<TData, TError>
450450

451-
export type MutationKey = string | unknown[]
451+
export type MutationKey = string | readonly unknown[]
452452

453453
export type MutationStatus = 'idle' | 'loading' | 'success' | 'error'
454454

@@ -463,7 +463,7 @@ export interface MutationOptions<
463463
TContext = unknown
464464
> {
465465
mutationFn?: MutationFunction<TData, TVariables>
466-
mutationKey?: string | unknown[]
466+
mutationKey?: MutationKey
467467
variables?: TVariables
468468
onMutate?: (variables: TVariables) => Promise<TContext> | TContext
469469
onSuccess?: (

src/core/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,8 @@ export function stableValueHash(value: any): string {
223223
* Checks if key `b` partially matches with key `a`.
224224
*/
225225
export function partialMatchKey(
226-
a: string | unknown[],
227-
b: string | unknown[]
226+
a: QueryKey,
227+
b: QueryKey
228228
): boolean {
229229
return partialDeepEqual(ensureArray(a), ensureArray(b))
230230
}

0 commit comments

Comments
 (0)