@@ -4,7 +4,7 @@ import { infiniteQueryOptions } from '../infiniteQueryOptions'
4
4
import { useInfiniteQuery } from '../useInfiniteQuery'
5
5
import { useSuspenseInfiniteQuery } from '../useSuspenseInfiniteQuery'
6
6
import { useQuery } from '../useQuery'
7
- import type { InfiniteData } from '@tanstack/query-core'
7
+ import type { InfiniteData , InitialDataFunction } from '@tanstack/query-core'
8
8
9
9
describe ( 'queryOptions' , ( ) => {
10
10
it ( 'should not allow excess properties' , ( ) => {
@@ -152,4 +152,23 @@ describe('queryOptions', () => {
152
152
// @ts -expect-error cannot pass infinite options to non-infinite query functions
153
153
queryClient . prefetchQuery ( options )
154
154
} )
155
+
156
+ test ( 'allow optional initialData' , ( ) => {
157
+ const initialData : { example : boolean } | undefined = { example : true }
158
+ const queryOptions = infiniteQueryOptions ( {
159
+ queryKey : [ 'example' ] ,
160
+ queryFn : async ( ) => initialData ,
161
+ // initialData below errors
162
+ initialData : initialData
163
+ ? ( ) => ( { pages : [ initialData ] , pageParams : [ ] } )
164
+ : undefined ,
165
+ getNextPageParam : ( ) => 1 ,
166
+ initialPageParam : 1 ,
167
+ } )
168
+ queryOptions . initialData
169
+ expectTypeOf ( queryOptions . initialData ) . toMatchTypeOf <
170
+ | InitialDataFunction < InfiniteData < { example : boolean } , number > >
171
+ | undefined
172
+ > ( )
173
+ } )
155
174
} )
0 commit comments