Skip to content

Commit 0298c90

Browse files
manudeliclaude
andauthored
test(query-core): keep setQueryData typecheck green on TypeScript 5.4 (#10985)
Under TypeScript 5.4, `NoInfer<T>` 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 <noreply@anthropic.com>
1 parent 4eb0ed9 commit 0298c90

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

packages/query-core/src/__tests__/queryClient.test-d.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,12 @@ describe('fully typed usage', () => {
283283
Array<[ReadonlyArray<unknown>, unknown]>
284284
>()
285285

286-
const queryData3 = queryClient.setQueryData(filterKey, { foo: '' })
286+
// Type the value before passing it: TypeScript 5.4's `NoInfer` can't match
287+
// an inline object literal against the value branch of the `Updater` union
288+
// here, so it falls back to the function branch and reports the literal as
289+
// excess properties. Annotating sidesteps that (TS >= 5.5 handles it).
290+
const newData: TData = { foo: '' }
291+
const queryData3 = queryClient.setQueryData(filterKey, newData)
287292
type SetQueryDataUpdaterArg = Parameters<
288293
typeof queryClient.setQueryData<unknown, typeof filterKey>
289294
>[1]

0 commit comments

Comments
 (0)