From 027689121f6f97a6539cbc41c9629592e48dd6a2 Mon Sep 17 00:00:00 2001 From: thribhuvan003 Date: Tue, 25 Aug 2026 21:18:29 +0530 Subject: [PATCH] fix(solid-query): allow optional initialData in infiniteQueryOptions UndefinedInitialDataInfiniteOptions typed initialData as `?: undefined`, so passing a value that may be undefined matched neither overload: the defined one rejects undefined, and the undefined one rejects the data. Callers had to cast or split the call. Widen the union to accept the data and its function form, matching the shape react-query has had since #8157 and mirroring solid's own DefinedInitialDataInfiniteOptions. --- .changeset/olive-pugs-repeat.md | 5 +++++ .../__tests__/infiniteQueryOptions.test-d.tsx | 19 +++++++++++++++++++ .../solid-query/src/infiniteQueryOptions.ts | 5 ++++- 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 .changeset/olive-pugs-repeat.md diff --git a/.changeset/olive-pugs-repeat.md b/.changeset/olive-pugs-repeat.md new file mode 100644 index 00000000000..99e5ae99947 --- /dev/null +++ b/.changeset/olive-pugs-repeat.md @@ -0,0 +1,5 @@ +--- +'@tanstack/solid-query': patch +--- + +Allow optional `initialData` in `infiniteQueryOptions`, matching react-query diff --git a/packages/solid-query/src/__tests__/infiniteQueryOptions.test-d.tsx b/packages/solid-query/src/__tests__/infiniteQueryOptions.test-d.tsx index be3a19cb97d..fb017d7411d 100644 --- a/packages/solid-query/src/__tests__/infiniteQueryOptions.test-d.tsx +++ b/packages/solid-query/src/__tests__/infiniteQueryOptions.test-d.tsx @@ -136,4 +136,23 @@ describe('infiniteQueryOptions', () => { }> >() }) + + it('should allow optional initialData object', () => { + const initialData = { wow: true } as { wow: boolean } | undefined + const options = infiniteQueryOptions({ + queryKey: queryKey(), + queryFn: () => initialData, + initialData: initialData + ? { pages: [initialData], pageParams: [] } + : undefined, + getNextPageParam: () => 1, + initialPageParam: 1, + }) + + expectTypeOf(options.initialData).toExtend< + | InfiniteData<{ wow: boolean } | undefined, number> + | (() => InfiniteData<{ wow: boolean } | undefined, number>) + | undefined + >() + }) }) diff --git a/packages/solid-query/src/infiniteQueryOptions.ts b/packages/solid-query/src/infiniteQueryOptions.ts index 1648882d2f3..984347653bf 100644 --- a/packages/solid-query/src/infiniteQueryOptions.ts +++ b/packages/solid-query/src/infiniteQueryOptions.ts @@ -16,7 +16,10 @@ export type UndefinedInitialDataInfiniteOptions< TPageParam = unknown, > = Accessor< InfiniteQueryOptions & { - initialData?: undefined + initialData?: + | undefined + | NonUndefinedGuard> + | (() => NonUndefinedGuard>) } >