From c74591ea22adedd1dd8402fb28a42c241db4e572 Mon Sep 17 00:00:00 2001 From: Wonsuk Choi Date: Wed, 23 Sep 2026 19:11:07 +0900 Subject: [PATCH] test({angular,vue,solid}-query/queryOptions): add type tests for an optional 'initialData' object (#11593) --- .../src/__tests__/query-options.test-d.ts | 13 +++++++++++++ .../src/__tests__/queryOptions.test-d.tsx | 13 +++++++++++++ .../vue-query/src/__tests__/queryOptions.test-d.ts | 13 +++++++++++++ 3 files changed, 39 insertions(+) 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 830e8df805..18f6499999 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 @@ -8,6 +8,7 @@ import { skipToken, } from '..' import type { Signal } from '@angular/core' +import type { InitialDataFunction } from '@tanstack/query-core' // Regression test for exported queryOptions inference under declaration emit. // TypeScript should be able to name the return type without expanding the @@ -56,6 +57,18 @@ describe('queryOptions', () => { { id: string; title: string } | undefined >() }) + + it('should allow optional initialData object', () => { + const options = queryOptions({ + queryKey: queryKey(), + queryFn: () => Promise.resolve('something string'), + initialData: Math.random() > 0.5 ? 'initial string' : undefined, + }) + + expectTypeOf(options.initialData).toExtend< + InitialDataFunction | string | undefined + >() + }) }) it('should work when passed to injectQuery', () => { diff --git a/packages/solid-query/src/__tests__/queryOptions.test-d.tsx b/packages/solid-query/src/__tests__/queryOptions.test-d.tsx index 033a6fc33a..468c5e8d0a 100644 --- a/packages/solid-query/src/__tests__/queryOptions.test-d.tsx +++ b/packages/solid-query/src/__tests__/queryOptions.test-d.tsx @@ -8,6 +8,7 @@ import { import { queryKey } from '@tanstack/query-test-utils' import { useQuery } from '../useQuery' import { queryOptions } from '../queryOptions' +import type { InitialDataFunction } from '@tanstack/query-core' // Regression test for exported queryOptions inference under declaration emit. // TypeScript should be able to name the return type without expanding the @@ -205,4 +206,16 @@ describe('queryOptions', () => { const data = queryClient.getQueryData(options.queryKey) expectTypeOf(data).toEqualTypeOf() }) + + it('should allow optional initialData object', () => { + const options = queryOptions({ + queryKey: queryKey(), + queryFn: () => Promise.resolve('something string'), + initialData: Math.random() > 0.5 ? 'initial string' : undefined, + }) + + expectTypeOf(options.initialData).toExtend< + InitialDataFunction | string | undefined + >() + }) }) diff --git a/packages/vue-query/src/__tests__/queryOptions.test-d.ts b/packages/vue-query/src/__tests__/queryOptions.test-d.ts index 077c435884..39302af001 100644 --- a/packages/vue-query/src/__tests__/queryOptions.test-d.ts +++ b/packages/vue-query/src/__tests__/queryOptions.test-d.ts @@ -5,6 +5,7 @@ import { queryKey } from '@tanstack/query-test-utils' import { QueryClient } from '../queryClient' import { queryOptions } from '../queryOptions' import { useQuery } from '../useQuery' +import type { InitialDataFunction } from '@tanstack/query-core' // Regression test for exported queryOptions inference under declaration emit. // TypeScript should be able to name the return type without expanding the @@ -262,6 +263,18 @@ describe('queryOptions', () => { expectTypeOf(data).toEqualTypeOf() }) + it('should allow optional initialData object', () => { + const options = queryOptions({ + queryKey: queryKey(), + queryFn: () => Promise.resolve('something string'), + initialData: Math.random() > 0.5 ? 'initial string' : undefined, + }) + + expectTypeOf(options.initialData).toExtend< + InitialDataFunction | string | undefined + >() + }) + it('should allow accessing queryFn and other properties on the returned options object', () => { const options = queryOptions({ queryKey: queryKey(),