Skip to content

Commit 97f4a62

Browse files
Fix PR
1 parent 7368bd0 commit 97f4a62

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

packages/angular-query-experimental/src/__tests__/query-options.test-d.ts

+19
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,25 @@ describe('queryOptions', () => {
2525
},
2626
})
2727
})
28+
29+
test('should allow undefined response in initialData', () => {
30+
return (id: string | null) =>
31+
queryOptions({
32+
queryKey: ['todo', id],
33+
queryFn: () =>
34+
Promise.resolve({
35+
id: '1',
36+
title: 'Do Laundry',
37+
}),
38+
initialData: () =>
39+
!id
40+
? undefined
41+
: {
42+
id,
43+
title: 'Initial Data',
44+
},
45+
})
46+
})
2847
})
2948

3049
test('should work when passed to injectQuery', () => {

packages/angular-query-experimental/src/query-options.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
import type { DataTag, DefaultError, QueryKey } from '@tanstack/query-core'
1+
import type {
2+
DataTag,
3+
DefaultError,
4+
InitialDataFunction,
5+
QueryKey,
6+
} from '@tanstack/query-core'
27
import type { CreateQueryOptions } from './types'
38

49
export type UndefinedInitialDataOptions<
@@ -7,7 +12,7 @@ export type UndefinedInitialDataOptions<
712
TData = TQueryFnData,
813
TQueryKey extends QueryKey = QueryKey,
914
> = CreateQueryOptions<TQueryFnData, TError, TData, TQueryKey> & {
10-
initialData?: undefined
15+
initialData?: undefined | InitialDataFunction<NonUndefinedGuard<TQueryFnData>>
1116
}
1217

1318
type NonUndefinedGuard<T> = T extends undefined ? never : T

0 commit comments

Comments
 (0)