|
1 |
| -import { describe, expectTypeOf, it } from 'vitest' |
| 1 | +import { assertType, describe, expectTypeOf, it } from 'vitest' |
2 | 2 | import { QueryClient } from '../queryClient'
|
3 | 3 | import type { MutationFilters, QueryFilters, Updater } from '../utils'
|
4 | 4 | import type { Mutation } from '../mutation'
|
@@ -42,10 +42,10 @@ describe('getQueryData', () => {
|
42 | 42 | })
|
43 | 43 |
|
44 | 44 | it('should only allow Arrays to be passed', () => {
|
45 |
| - const queryKey = 'key' |
46 |
| - const queryClient = new QueryClient() |
47 |
| - // @ts-expect-error TS2345: Argument of type 'string' is not assignable to parameter of type 'QueryKey' |
48 |
| - return queryClient.getQueryData(queryKey) |
| 45 | + assertType<Parameters<QueryClient['getQueryData']>>([ |
| 46 | + // @ts-expect-error TS2345: Argument of type 'string' is not assignable to parameter of type 'QueryKey' |
| 47 | + { queryKey: 'key' }, |
| 48 | + ]) |
49 | 49 | })
|
50 | 50 | })
|
51 | 51 |
|
@@ -171,22 +171,26 @@ describe('fetchInfiniteQuery', () => {
|
171 | 171 | })
|
172 | 172 |
|
173 | 173 | it('should not allow passing getNextPageParam without pages', () => {
|
174 |
| - new QueryClient().fetchInfiniteQuery({ |
175 |
| - queryKey: ['key'], |
176 |
| - queryFn: () => Promise.resolve('string'), |
177 |
| - initialPageParam: 1, |
178 |
| - getNextPageParam: () => 1, |
179 |
| - }) |
| 174 | + assertType<Parameters<QueryClient['fetchInfiniteQuery']>>([ |
| 175 | + { |
| 176 | + queryKey: ['key'], |
| 177 | + queryFn: () => Promise.resolve('string'), |
| 178 | + initialPageParam: 1, |
| 179 | + getNextPageParam: () => 1, |
| 180 | + }, |
| 181 | + ]) |
180 | 182 | })
|
181 | 183 |
|
182 | 184 | it('should not allow passing pages without getNextPageParam', () => {
|
183 |
| - // @ts-expect-error Property 'getNextPageParam' is missing |
184 |
| - return new QueryClient().fetchInfiniteQuery({ |
185 |
| - queryKey: ['key'], |
186 |
| - queryFn: () => Promise.resolve('string'), |
187 |
| - initialPageParam: 1, |
188 |
| - pages: 5, |
189 |
| - }) |
| 185 | + assertType<Parameters<QueryClient['fetchInfiniteQuery']>>([ |
| 186 | + // @ts-expect-error Property 'getNextPageParam' is missing |
| 187 | + { |
| 188 | + queryKey: ['key'], |
| 189 | + queryFn: () => Promise.resolve('string'), |
| 190 | + initialPageParam: 1, |
| 191 | + pages: 5, |
| 192 | + }, |
| 193 | + ]) |
190 | 194 | })
|
191 | 195 | })
|
192 | 196 |
|
@@ -506,26 +510,17 @@ describe('fully typed usage', () => {
|
506 | 510 |
|
507 | 511 | describe('invalidateQueries', () => {
|
508 | 512 | it('shows type error when queryKey is a wrong type in invalidateQueries', () => {
|
509 |
| - const queryClient = new QueryClient() |
510 |
| - |
511 |
| - queryClient.invalidateQueries() |
512 |
| - |
513 |
| - queryClient.invalidateQueries({ |
514 |
| - queryKey: ['1'], |
515 |
| - }) |
516 |
| - |
517 |
| - queryClient.invalidateQueries({ |
| 513 | + assertType<Parameters<QueryClient['invalidateQueries']>>([]) |
| 514 | + assertType<Parameters<QueryClient['invalidateQueries']>>([ |
| 515 | + { queryKey: ['1'] }, |
| 516 | + ]) |
| 517 | + assertType<Parameters<QueryClient['invalidateQueries']>>([ |
518 | 518 | // @ts-expect-error
|
519 |
| - queryKey: '1', |
520 |
| - }) |
521 |
| - |
522 |
| - queryClient.invalidateQueries({ |
523 |
| - // @ts-expect-error |
524 |
| - queryKey: {}, |
525 |
| - }) |
| 519 | + { queryKey: '1' }, |
| 520 | + ]) |
526 | 521 | })
|
527 | 522 | it('needs queryKey to be an array (#8684)', () => {
|
528 |
| - new QueryClient().invalidateQueries({ |
| 523 | + assertType<Parameters<QueryClient['invalidateQueries']>>({ |
529 | 524 | // @ts-expect-error key is not an array
|
530 | 525 | queryKey: { foo: true },
|
531 | 526 | })
|
|
0 commit comments