From 00c3c8c1c82902a0dd47a28ef53717d9897b8e97 Mon Sep 17 00:00:00 2001 From: Wonsuk Choi Date: Tue, 16 Jun 2026 17:37:30 +0900 Subject: [PATCH] test(solid-query/useQuery): add type test for generic indexed-access 'TData' regression guard --- .../src/__tests__/useQuery.test-d.tsx | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/packages/solid-query/src/__tests__/useQuery.test-d.tsx b/packages/solid-query/src/__tests__/useQuery.test-d.tsx index 08fb3f17bc..278f4710b8 100644 --- a/packages/solid-query/src/__tests__/useQuery.test-d.tsx +++ b/packages/solid-query/src/__tests__/useQuery.test-d.tsx @@ -250,4 +250,52 @@ describe('useQuery', () => { }) }) }) + + describe('generic indexed access TData', () => { + // https://github.com/TanStack/query/issues/9937 + it('should be assignable back to its source indexed type when passed to a generic function parameter', () => { + enum DataType { + Account = 'account', + Product = 'product', + } + + interface Account { + name: string + } + interface Product { + code: string + } + + type DataTypeToEntity = { + [DataType.Account]: Account + [DataType.Product]: Product + } + + const getData = ( + _dataType: TDataType, + ): Promise => + Promise.resolve({} as DataTypeToEntity[TDataType]) + + const getLabel = ( + _dataType: TDataType, + _data: DataTypeToEntity[TDataType], + ) => 'test' + + function Test(props: { + dataType: TDataType + }) { + const { data } = useQuery(() => ({ + queryKey: ['test'], + queryFn: () => getData(props.dataType), + })) + + // Regression guard: this call must compile. With the previous + // hand-rolled NoInfer, `data` failed to flow back into the generic + // indexed-access parameter `DataTypeToEntity[TDataType]`. + return data ? getLabel(props.dataType, data) : null + } + + expectTypeOf(Test).toBeFunction() + }) + }) })