Skip to content

Commit 7a0f865

Browse files
committed
fix(query-core): allow partial query keys in QueryFilters and MutationFilters
Add a type to match tuple prefixes to match partial query keys in `QueryFilters` and `MutationFilters` Fixes TanStack#9680
1 parent cd29063 commit 7a0f865

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

packages/query-core/src/types.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,16 @@ export type Override<TTargetA, TTargetB> = {
3636

3737
export type NoInfer<T> = [T][T extends any ? 0 : never]
3838

39+
export type DropLast<T extends ReadonlyArray<unknown>> = T extends readonly [
40+
...infer R,
41+
unknown,
42+
]
43+
? R
44+
: never
45+
46+
export type TuplePrefixes<T extends ReadonlyArray<unknown>> =
47+
T extends readonly [] ? readonly [] : TuplePrefixes<DropLast<T>> | T
48+
3949
export interface Register {
4050
// defaultError: Error
4151
// queryMeta: Record<string, unknown>

packages/query-core/src/utils.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import type {
1010
QueryOptions,
1111
StaleTime,
1212
StaleTimeFunction,
13+
TuplePrefixes,
1314
} from './types'
1415
import type { Mutation } from './mutation'
1516
import type { FetchOptions, Query } from './query'
@@ -32,7 +33,7 @@ export interface QueryFilters<TQueryKey extends QueryKey = QueryKey> {
3233
/**
3334
* Include queries matching this query key
3435
*/
35-
queryKey?: TQueryKey
36+
queryKey?: TuplePrefixes<TQueryKey>
3637
/**
3738
* Include or exclude stale queries
3839
*/
@@ -62,7 +63,7 @@ export interface MutationFilters<
6263
/**
6364
* Include mutations matching this mutation key
6465
*/
65-
mutationKey?: MutationKey
66+
mutationKey?: TuplePrefixes<MutationKey>
6667
/**
6768
* Filter by mutation status
6869
*/

0 commit comments

Comments
 (0)