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