test(query-core): keep setQueryData typecheck green on TypeScript 5.4#10985
Conversation
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>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe TypeScript test for ChangesTyped
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
|
View your CI Pipeline Execution ↗ for commit 8396e55
☁️ Nx Cloud last updated this comment at |
🚀 Changeset Version PreviewNo changeset entries found. Merging this PR will not cause a version bump for any packages. |
There was a problem hiding this comment.
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 callingsetQueryData. - 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.
size-limit report 📦
|
🎯 Problem
The
test:types:ts54legacy typecheck fails on asetQueryDatatype test inquery-core:Under TypeScript 5.4,
NoInfer<T>can't match an inline object literal against the value branch of theUpdaterunion insetQueryData, 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
mainunnoticedquery-core's owntest:typesexcludessrc/__tests__, so its task is green.react-query-persist-client/react-query-devtoolstest:typesbuildquery-core's test sources transitively.tscnever 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 editedreact-querytest-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.4NoInferlimitation while preserving the existing assertions (return type + updater-arg type):✅ 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-clientand@tanstack/react-query-devtoolstest:typeslocally — 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:ts54instead — happy to do that if preferred. Flagging because the underlying limitation is real: a user on TS 5.4 passing an inline object literal tosetQueryDatawould hit the same error.🚀 Release Impact
Summary by CodeRabbit