Open History to see the last commit
1import { describe, expectTypeOf, it } from 'vitest'
2import { dataTagSymbol } from '@tanstack/query-core'
3import { useInfiniteQuery } from '../useInfiniteQuery'
4import { infiniteQueryOptions } from '../infiniteQueryOptions'
5import type { InfiniteData } from '@tanstack/query-core'
6import type {
7 DefinedInitialDataInfiniteOptions,
8 UndefinedInitialDataInfiniteOptions,
9} from '../infiniteQueryOptions'
10β
11describe('infiniteQueryOptions', () => {
12 it('should infer defined types', () => {
13 const options = infiniteQueryOptions({
14 getNextPageParam: () => 10,
15 queryKey: ['key'],
16 queryFn: () => ({ wow: true }),
17 initialData: {
18 pageParams: [undefined],
19 pages: [{ wow: true }],
20 },
21 initialPageParam: 0,
22 })
23β
24 expectTypeOf(useInfiniteQuery(() => options).data).toEqualTypeOf<
25 InfiniteData<{ wow: boolean }, unknown>
26 >()
27β
28 expectTypeOf(options).toMatchTypeOf<
29 ReturnType<
30 DefinedInitialDataInfiniteOptions<
31 { wow: boolean },
32 Error,
33 InfiniteData<{ wow: boolean }, unknown>,
34 Array<string>,
35 number | undefined
36 >
37 >
38 >()
39β
40 expectTypeOf(options.queryKey[dataTagSymbol]).toEqualTypeOf<
41 InfiniteData<{ wow: boolean }>
42 >()
43 })
44β
45 it('should work without defined types', () => {
46 const options = infiniteQueryOptions({
47 getNextPageParam: () => undefined,
48 queryKey: ['key'],
49 queryFn: () => ({ wow: true }),
50 initialPageParam: 0,
51 })
52β
53 expectTypeOf(() => useInfiniteQuery(() => options).data).toEqualTypeOf<
54 () => InfiniteData<{ wow: boolean }, unknown> | undefined
55 >()
56β
57 expectTypeOf(options).toMatchTypeOf<
58 ReturnType<
59 UndefinedInitialDataInfiniteOptions<
60 { wow: boolean },
61 Error,
62 InfiniteData<{ wow: boolean }, unknown>,
63 Array<string>,
64 number
65 >
66 >
67 >()
68β
69 expectTypeOf(options.queryKey[dataTagSymbol]).toEqualTypeOf<
70 InfiniteData<{
71 wow: boolean
72 }>
73 >()
74 })
75})