From 8396e5582144340da98182e74ce0fb1212035908 Mon Sep 17 00:00:00 2001 From: Jonghyeon Ko Date: Fri, 26 Jun 2026 00:35:10 +0900 Subject: [PATCH] test(query-core): keep setQueryData typecheck green on TypeScript 5.4 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Under TypeScript 5.4, `NoInfer` can't match an inline object literal against the value branch of the `Updater` union in `setQueryData`, so it falls back to the function branch and reports the literal as excess properties (TS2353). TS >= 5.5 handles it correctly. This surfaces in the `test:types:ts54` legacy typecheck via the project reference chain (e.g. react-query-persist-client / react-query-devtools build query-core's test sources). It is normally masked by the Nx remote cache and only re-runs — and fails — when a dependent package's type inputs change, so it can land on `main` unnoticed. Annotate the value before passing it to `setQueryData` to sidestep the 5.4 limitation while preserving the assertions. Verified across TS 5.4–6.0. Co-Authored-By: Claude Opus 4.8 --- packages/query-core/src/__tests__/queryClient.test-d.tsx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/query-core/src/__tests__/queryClient.test-d.tsx b/packages/query-core/src/__tests__/queryClient.test-d.tsx index 4cd092ddd64..866d1d5f775 100644 --- a/packages/query-core/src/__tests__/queryClient.test-d.tsx +++ b/packages/query-core/src/__tests__/queryClient.test-d.tsx @@ -283,7 +283,12 @@ describe('fully typed usage', () => { Array<[ReadonlyArray, unknown]> >() - const queryData3 = queryClient.setQueryData(filterKey, { foo: '' }) + // Type the value before passing it: TypeScript 5.4's `NoInfer` can't match + // an inline object literal against the value branch of the `Updater` union + // here, so it falls back to the function branch and reports the literal as + // excess properties. Annotating sidesteps that (TS >= 5.5 handles it). + const newData: TData = { foo: '' } + const queryData3 = queryClient.setQueryData(filterKey, newData) type SetQueryDataUpdaterArg = Parameters< typeof queryClient.setQueryData >[1]