Skip to content

Commit 329b5f8

Browse files
jimmycallinTkDodo
andauthoredOct 9, 2024··
fix: allow optional initialData object (#8157)
Co-authored-by: Dominik Dorfmeister <office@dorfmeister.cc>
1 parent eb341fc commit 329b5f8

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed
 

‎packages/react-query/src/__tests__/infiniteQueryOptions.test-d.tsx

+22-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ describe('queryOptions', () => {
153153
queryClient.prefetchQuery(options)
154154
})
155155

156-
test('allow optional initialData', () => {
156+
test('allow optional initialData function', () => {
157157
const initialData: { example: boolean } | undefined = { example: true }
158158
const queryOptions = infiniteQueryOptions({
159159
queryKey: ['example'],
@@ -168,6 +168,27 @@ describe('queryOptions', () => {
168168
queryOptions.initialData
169169
expectTypeOf(queryOptions.initialData).toMatchTypeOf<
170170
| 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>
171192
| undefined
172193
>()
173194
})

‎packages/react-query/src/infiniteQueryOptions.ts

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export type UndefinedInitialDataInfiniteOptions<
2323
> & {
2424
initialData?:
2525
| undefined
26+
| NonUndefinedGuard<InfiniteData<TQueryFnData, TPageParam>>
2627
| InitialDataFunction<
2728
NonUndefinedGuard<InfiniteData<TQueryFnData, TPageParam>>
2829
>

0 commit comments

Comments
 (0)
Please sign in to comment.