Skip to content

test(query-core): keep setQueryData typecheck green on TypeScript 5.4#10985

Merged
manudeli merged 1 commit into
mainfrom
fix/query-core-setquerydata-ts54-typecheck
Jun 25, 2026
Merged

test(query-core): keep setQueryData typecheck green on TypeScript 5.4#10985
manudeli merged 1 commit into
mainfrom
fix/query-core-setquerydata-ts54-typecheck

Conversation

@manudeli

@manudeli manudeli commented Jun 25, 2026

Copy link
Copy Markdown
Collaborator

🎯 Problem

The test:types:ts54 legacy typecheck fails on a setQueryData type test in query-core:

packages/query-core/src/__tests__/queryClient.test-d.tsx(286,62): error TS2353:
Object literal may only specify known properties, and 'foo' does not exist in type
'(input: NoInfer<TData> | undefined) => NoInfer<TData> | undefined'.

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. TS ≥ 5.5 handles it correctly.

Why it lands on main unnoticed

  • query-core's own test:types excludes src/__tests__, so its task is green.
  • The error only appears through the project-reference chain — e.g. react-query-persist-client / react-query-devtools test:types build query-core's test sources transitively.
  • Those tasks are normally served from the Nx remote cache, so the legacy tsc never re-runs. They only re-execute (and fail) when a dependent package's type inputs change — which is exactly what happened on an unrelated docs PR that edited react-query test-d files.

So this is a pre-existing latent failure, not introduced by any one PR.

🔧 Change

Annotate the value before passing it to setQueryData, which sidesteps the 5.4 NoInfer limitation while preserving the existing assertions (return type + updater-arg type):

-    const queryData3 = queryClient.setQueryData(filterKey, { foo: '' })
+    const newData: TData = { foo: '' }
+    const queryData3 = queryClient.setQueryData(filterKey, newData)

✅ Verification

Ran the isolated query-core typecheck (incl. __tests__) across the full matrix — TS 5.4, 5.5, 5.6, 5.8, 5.9, 6.0 all pass. Also re-ran the originally-failing @tanstack/react-query-persist-client and @tanstack/react-query-devtools test:types locally — both green.

💬 Note for maintainers

This keeps TS 5.4 in the support matrix. If 5.4 is no longer a target, an alternative would be to drop test:types:ts54 instead — happy to do that if preferred. Flagging because the underlying limitation is real: a user on TS 5.4 passing an inline object literal to setQueryData would hit the same error.

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.
  • This change is docs/CI/dev-only (no release).

Summary by CodeRabbit

  • Tests
    • Improved TypeScript coverage for query data updates, including better handling of inline object values.
    • Added checks for newer TypeScript inference behavior to keep type validation reliable.

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>
@coderabbitai

coderabbitai Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 25d048ac-d52a-4a79-85cb-2bfccb285202

📥 Commits

Reviewing files that changed from the base of the PR and between 4eb0ed9 and 8396e55.

📒 Files selected for processing (1)
  • packages/query-core/src/__tests__/queryClient.test-d.tsx

📝 Walkthrough

Walkthrough

The TypeScript test for queryClient.setQueryData now uses a typed newData variable before passing the value into the call. Comments were added to document the inference behavior being exercised.

Changes

Typed setQueryData inference test

Layer / File(s) Summary
Typed data assignment
packages/query-core/src/__tests__/queryClient.test-d.tsx
The queryData3 test now stores { foo: '' } in a TData variable before calling setQueryData, and adds comments about Updater union inference.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Suggested labels

package: query-core

Suggested reviewers

  • TkDodo

Poem

A bunny hops through type-check code,
With newData set, the path is glowed.
Tiny tests squeak, inference sings,
While QueryCore adjusts small things. 🐇

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main fix: a TypeScript 5.4 typecheck issue in query-core's setQueryData test.
Description check ✅ Passed The description covers the problem, change, verification, and release impact, though the checklist template section is missing.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/query-core-setquerydata-ts54-typecheck

Comment @coderabbitai help to get the list of available commands.

@nx-cloud

nx-cloud Bot commented Jun 25, 2026

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit 8396e55

Command Status Duration Result
nx affected --targets=test:sherif,test:knip,tes... ✅ Succeeded 6m 32s View ↗
nx run-many --target=build --exclude=examples/*... ✅ Succeeded 1m 53s View ↗

☁️ Nx Cloud last updated this comment at 2026-06-25 15:43:22 UTC

@github-actions

Copy link
Copy Markdown
Contributor

🚀 Changeset Version Preview

No changeset entries found. Merging this PR will not cause a version bump for any packages.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates a query-core type-level test to avoid a TypeScript 5.4 inference limitation around NoInfer<T> and the Updater union used by QueryClient#setQueryData, keeping the legacy test:types:ts54 check green when __tests__ are included via project references.

Changes:

  • Introduces an explicitly typed intermediate variable (newData: TData) before calling setQueryData.
  • Adds an inline comment explaining the TS 5.4-specific inference/excess-property behavior and why the annotation is necessary.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@pkg-pr-new

pkg-pr-new Bot commented Jun 25, 2026

Copy link
Copy Markdown
More templates

@tanstack/angular-query-experimental

npm i https://pkg.pr.new/@tanstack/angular-query-experimental@10985

@tanstack/eslint-plugin-query

npm i https://pkg.pr.new/@tanstack/eslint-plugin-query@10985

@tanstack/lit-query

npm i https://pkg.pr.new/@tanstack/lit-query@10985

@tanstack/preact-query

npm i https://pkg.pr.new/@tanstack/preact-query@10985

@tanstack/preact-query-devtools

npm i https://pkg.pr.new/@tanstack/preact-query-devtools@10985

@tanstack/preact-query-persist-client

npm i https://pkg.pr.new/@tanstack/preact-query-persist-client@10985

@tanstack/query-async-storage-persister

npm i https://pkg.pr.new/@tanstack/query-async-storage-persister@10985

@tanstack/query-broadcast-client-experimental

npm i https://pkg.pr.new/@tanstack/query-broadcast-client-experimental@10985

@tanstack/query-core

npm i https://pkg.pr.new/@tanstack/query-core@10985

@tanstack/query-devtools

npm i https://pkg.pr.new/@tanstack/query-devtools@10985

@tanstack/query-persist-client-core

npm i https://pkg.pr.new/@tanstack/query-persist-client-core@10985

@tanstack/query-sync-storage-persister

npm i https://pkg.pr.new/@tanstack/query-sync-storage-persister@10985

@tanstack/react-query

npm i https://pkg.pr.new/@tanstack/react-query@10985

@tanstack/react-query-devtools

npm i https://pkg.pr.new/@tanstack/react-query-devtools@10985

@tanstack/react-query-next-experimental

npm i https://pkg.pr.new/@tanstack/react-query-next-experimental@10985

@tanstack/react-query-persist-client

npm i https://pkg.pr.new/@tanstack/react-query-persist-client@10985

@tanstack/solid-query

npm i https://pkg.pr.new/@tanstack/solid-query@10985

@tanstack/solid-query-devtools

npm i https://pkg.pr.new/@tanstack/solid-query-devtools@10985

@tanstack/solid-query-persist-client

npm i https://pkg.pr.new/@tanstack/solid-query-persist-client@10985

@tanstack/svelte-query

npm i https://pkg.pr.new/@tanstack/svelte-query@10985

@tanstack/svelte-query-devtools

npm i https://pkg.pr.new/@tanstack/svelte-query-devtools@10985

@tanstack/svelte-query-persist-client

npm i https://pkg.pr.new/@tanstack/svelte-query-persist-client@10985

@tanstack/vue-query

npm i https://pkg.pr.new/@tanstack/vue-query@10985

@tanstack/vue-query-devtools

npm i https://pkg.pr.new/@tanstack/vue-query-devtools@10985

commit: 8396e55

@github-actions

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size
react full 12.13 KB (0%)
react minimal 9.08 KB (0%)

@manudeli manudeli merged commit 0298c90 into main Jun 25, 2026
10 checks passed
@manudeli manudeli deleted the fix/query-core-setquerydata-ts54-typecheck branch June 25, 2026 15:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants