Open History to see the last commit
1import type {
2 DataTag,
3 DefaultError,
4 InfiniteData,
5 InitialDataFunction,
6 OmitKeyof,
7 QueryKey,
8 SkipToken,
9} from '@tanstack/query-core'
10import type { CreateInfiniteQueryOptions } from './types'
11β
12export type UndefinedInitialDataInfiniteOptions<
13 TQueryFnData,
14 TError = DefaultError,
15 TData = InfiniteData<TQueryFnData>,
16 TQueryKey extends QueryKey = QueryKey,
17 TPageParam = unknown,
18> = CreateInfiniteQueryOptions<
19 TQueryFnData,
20 TError,
21 TData,
22 TQueryFnData,
23 TQueryKey,
24 TPageParam
25> & {
26 initialData?:
27 | undefined
28 | NonUndefinedGuard<InfiniteData<TQueryFnData, TPageParam>>
29 | InitialDataFunction<
30 NonUndefinedGuard<InfiniteData<TQueryFnData, TPageParam>>
31 >
32}
33β
34export type UnusedSkipTokenInfiniteOptions<
35 TQueryFnData,
36 TError = DefaultError,
37 TData = InfiniteData<TQueryFnData>,
38 TQueryKey extends QueryKey = QueryKey,
39 TPageParam = unknown,
40> = OmitKeyof<
41 CreateInfiniteQueryOptions<
42 TQueryFnData,
43 TError,
44 TData,
45 TQueryFnData,
46 TQueryKey,
47 TPageParam
48 >,
49 'queryFn'
50> & {
51 queryFn?: Exclude<
52 CreateInfiniteQueryOptions<
53 TQueryFnData,
54 TError,
55 TData,
56 TQueryFnData,
57 TQueryKey,
58 TPageParam
59 >['queryFn'],
60 SkipToken | undefined
61 >
62}
63β
64type NonUndefinedGuard<T> = T extends undefined ? never : T
65β
66export type DefinedInitialDataInfiniteOptions<
67 TQueryFnData,
68 TError = DefaultError,
69 TData = InfiniteData<TQueryFnData>,
70 TQueryKey extends QueryKey = QueryKey,
71 TPageParam = unknown,
72> = CreateInfiniteQueryOptions<
73 TQueryFnData,
74 TError,
75 TData,
76 TQueryFnData,
77 TQueryKey,
78 TPageParam
79> & {
80 initialData:
81 | NonUndefinedGuard<InfiniteData<TQueryFnData, TPageParam>>
82 | (() => NonUndefinedGuard<InfiniteData<TQueryFnData, TPageParam>>)
83 | undefined
84}
85β
86/**
87 * Allows to share and re-use infinite query options in a type-safe way.
88 *
89 * The `queryKey` will be tagged with the type from `queryFn`.
90 * @param options - The infinite query options to tag with the type from `queryFn`.
91 * @returns The tagged infinite query options.
92 * @public
93 */
94export function infiniteQueryOptions<
95 TQueryFnData,
96 TError = DefaultError,
97 TData = InfiniteData<TQueryFnData>,
98 TQueryKey extends QueryKey = QueryKey,
99 TPageParam = unknown,
100>(
101 options: DefinedInitialDataInfiniteOptions<
102 TQueryFnData,
103 TError,
104 TData,
105 TQueryKey,
106 TPageParam
107 >,
108): DefinedInitialDataInfiniteOptions<
109 TQueryFnData,
110 TError,
111 TData,
112 TQueryKey,
113 TPageParam
114> & {
115 queryKey: DataTag<TQueryKey, InfiniteData<TQueryFnData>, TError>
116}
117β
118/**
119 * Allows to share and re-use infinite query options in a type-safe way.
120 *
121 * The `queryKey` will be tagged with the type from `queryFn`.
122 * @param options - The infinite query options to tag with the type from `queryFn`.
123 * @returns The tagged infinite query options.
124 * @public
125 */
126export function infiniteQueryOptions<
127 TQueryFnData,
128 TError = DefaultError,
129 TData = InfiniteData<TQueryFnData>,
130 TQueryKey extends QueryKey = QueryKey,
131 TPageParam = unknown,
132>(
133 options: UnusedSkipTokenInfiniteOptions<
134 TQueryFnData,
135 TError,
136 TData,
137 TQueryKey,
138 TPageParam
139 >,
140): UnusedSkipTokenInfiniteOptions<
141 TQueryFnData,
142 TError,
143 TData,
144 TQueryKey,
145 TPageParam
146> & {
147 queryKey: DataTag<TQueryKey, InfiniteData<TQueryFnData>, TError>
148}
149β
150/**
151 * Allows to share and re-use infinite query options in a type-safe way.
152 *
153 * The `queryKey` will be tagged with the type from `queryFn`.
154 * @param options - The infinite query options to tag with the type from `queryFn`.
155 * @returns The tagged infinite query options.
156 * @public
157 */
158export function infiniteQueryOptions<
159 TQueryFnData,
160 TError = DefaultError,
161 TData = InfiniteData<TQueryFnData>,
162 TQueryKey extends QueryKey = QueryKey,
163 TPageParam = unknown,
164>(
165 options: UndefinedInitialDataInfiniteOptions<
166 TQueryFnData,
167 TError,
168 TData,
169 TQueryKey,
170 TPageParam
171 >,
172): UndefinedInitialDataInfiniteOptions<
173 TQueryFnData,
174 TError,
175 TData,
176 TQueryKey,
177 TPageParam
178> & {
179 queryKey: DataTag<TQueryKey, InfiniteData<TQueryFnData>, TError>
180}
181β
182/**
183 * Allows to share and re-use infinite query options in a type-safe way.
184 *
185 * The `queryKey` will be tagged with the type from `queryFn`.
186 * @param options - The infinite query options to tag with the type from `queryFn`.
187 * @returns The tagged infinite query options.
188 * @public
189 */
190export function infiniteQueryOptions(options: unknown) {
191 return options
192}