@@ -153,7 +153,7 @@ describe('queryOptions', () => {
153
153
queryClient . prefetchQuery ( options )
154
154
} )
155
155
156
- test ( 'allow optional initialData' , ( ) => {
156
+ test ( 'allow optional initialData function ' , ( ) => {
157
157
const initialData : { example : boolean } | undefined = { example : true }
158
158
const queryOptions = infiniteQueryOptions ( {
159
159
queryKey : [ 'example' ] ,
@@ -168,6 +168,27 @@ describe('queryOptions', () => {
168
168
queryOptions . initialData
169
169
expectTypeOf ( queryOptions . initialData ) . toMatchTypeOf <
170
170
| InitialDataFunction < InfiniteData < { example : boolean } , number > >
171
+ | InfiniteData < { example : boolean } , number >
172
+ | undefined
173
+ > ( )
174
+ } )
175
+
176
+ test ( 'allow optional initialData object' , ( ) => {
177
+ const initialData : { example : boolean } | undefined = { example : true }
178
+ const queryOptions = infiniteQueryOptions ( {
179
+ queryKey : [ 'example' ] ,
180
+ queryFn : async ( ) => initialData ,
181
+ // initialData below errors
182
+ initialData : initialData
183
+ ? { pages : [ initialData ] , pageParams : [ ] }
184
+ : undefined ,
185
+ getNextPageParam : ( ) => 1 ,
186
+ initialPageParam : 1 ,
187
+ } )
188
+ queryOptions . initialData
189
+ expectTypeOf ( queryOptions . initialData ) . toMatchTypeOf <
190
+ | InitialDataFunction < InfiniteData < { example : boolean } , number > >
191
+ | InfiniteData < { example : boolean } , number >
171
192
| undefined
172
193
> ( )
173
194
} )
0 commit comments