Skip to content

Commit

Permalink
Fix PR
Browse files Browse the repository at this point in the history
  • Loading branch information
ShacharHarshuv committed Apr 29, 2024
1 parent 7368bd0 commit 97f4a62
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,25 @@ describe('queryOptions', () => {
},
})
})

test('should allow undefined response in initialData', () => {
return (id: string | null) =>
queryOptions({
queryKey: ['todo', id],
queryFn: () =>
Promise.resolve({
id: '1',
title: 'Do Laundry',
}),
initialData: () =>
!id
? undefined
: {
id,
title: 'Initial Data',
},
})
})
})

test('should work when passed to injectQuery', () => {
Expand Down
9 changes: 7 additions & 2 deletions packages/angular-query-experimental/src/query-options.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import type { DataTag, DefaultError, QueryKey } from '@tanstack/query-core'
import type {
DataTag,
DefaultError,
InitialDataFunction,
QueryKey,
} from '@tanstack/query-core'
import type { CreateQueryOptions } from './types'

export type UndefinedInitialDataOptions<
Expand All @@ -7,7 +12,7 @@ export type UndefinedInitialDataOptions<
TData = TQueryFnData,
TQueryKey extends QueryKey = QueryKey,
> = CreateQueryOptions<TQueryFnData, TError, TData, TQueryKey> & {
initialData?: undefined
initialData?: undefined | InitialDataFunction<NonUndefinedGuard<TQueryFnData>>
}

type NonUndefinedGuard<T> = T extends undefined ? never : T
Expand Down

0 comments on commit 97f4a62

Please sign in to comment.