Skip to content

Commit 8e2e174

Browse files
authored
fix(types): do not drop readonly for partial QueryFilter matching (#9878)
* fix(types): do not drop readonly for partial QueryFilter matching * fix(types): allow QueryFilters union with different lengths * Create orange-boxes-visit.md * Apply suggestion from @TkDodo
1 parent 6226325 commit 8e2e174

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

.changeset/orange-boxes-visit.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@tanstack/query-core": patch
3+
---
4+
5+
fix(types): allow QueryFilters union with different lengths

packages/query-core/src/__tests__/utils.test-d.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,19 @@ describe('QueryFilters', () => {
7373
>()
7474
})
7575

76+
// we test that there are not type errors here
77+
// eslint-disable-next-line vitest/expect-expect
78+
it('should work with unions of different lengths', () => {
79+
type Key =
80+
| readonly ['foo']
81+
| readonly ['foo', 'bar']
82+
| readonly ['foo', 'bar', 'baz']
83+
84+
const queryKey: Key = ['foo', 'bar'] as any as Key
85+
86+
new QueryClient().invalidateQueries({ queryKey })
87+
})
88+
7689
it('should error on invalid query keys', () => {
7790
assertType<QueryFilters<readonly ['key', { a: number; b: string }]>>({
7891
// @ts-expect-error cannot pass invalid query key

packages/query-core/src/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export interface QueryFilters<TQueryKey extends QueryKey = QueryKey> {
4343
/**
4444
* Include queries matching this query key
4545
*/
46-
queryKey?: TuplePrefixes<TQueryKey>
46+
queryKey?: TQueryKey | TuplePrefixes<TQueryKey>
4747
/**
4848
* Include or exclude stale queries
4949
*/

0 commit comments

Comments
 (0)