From 97f4a624eb7b1f3c7cab360bf34cada72e36c191 Mon Sep 17 00:00:00 2001 From: ShacharHarshuv Date: Mon, 29 Apr 2024 10:49:14 -0400 Subject: [PATCH] Fix PR --- .../src/__tests__/query-options.test-d.ts | 19 +++++++++++++++++++ .../src/query-options.ts | 9 +++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/packages/angular-query-experimental/src/__tests__/query-options.test-d.ts b/packages/angular-query-experimental/src/__tests__/query-options.test-d.ts index 4afe19c2af..5ec64e83bb 100644 --- a/packages/angular-query-experimental/src/__tests__/query-options.test-d.ts +++ b/packages/angular-query-experimental/src/__tests__/query-options.test-d.ts @@ -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', () => { diff --git a/packages/angular-query-experimental/src/query-options.ts b/packages/angular-query-experimental/src/query-options.ts index 7e958f3df7..1060a85b06 100644 --- a/packages/angular-query-experimental/src/query-options.ts +++ b/packages/angular-query-experimental/src/query-options.ts @@ -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< @@ -7,7 +12,7 @@ export type UndefinedInitialDataOptions< TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey, > = CreateQueryOptions & { - initialData?: undefined + initialData?: undefined | InitialDataFunction> } type NonUndefinedGuard = T extends undefined ? never : T