fix(svelte-query): wrap TData in NoInfer on query return types (#7673)#10578
fix(svelte-query): wrap TData in NoInfer on query return types (#7673)#10578ousamabenyounes wants to merge 1 commit intoTanStack:mainfrom
Conversation
…ack#7673) The original report (TanStack#7673) showed `select`'s `data` parameter typed as `any` when wrapping options in a Svelte 4 `derived` store. Svelte 5 removed that store-based API and the basic case now infers correctly, but `createQuery` / `createInfiniteQuery` still let TypeScript widen `TData` from the result-type annotation, unlike `react-query`, `preact-query`, and `vue-query` which all wrap `TData` in `NoInfer`. Aligning svelte-query with the rest of the ecosystem ensures `TData` comes from the input options only, locking in the inferred `select` result and preventing silent widening when the call site is annotated. Adds three type tests covering: select inference from queryFn return, select inference when spreading queryOptions, and the negative case where a wrong result-type annotation must not widen TData. Generated by Claude Code Vibe coded by ousamabenyounes Co-Authored-By: Claude <noreply@anthropic.com>
📝 WalkthroughWalkthroughThe PR updates svelte-query's Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
View your CI Pipeline Execution ↗ for commit 562030d
☁️ Nx Cloud last updated this comment at |
Summary
Fixes #7673.
The original report showed
select'sdataparameter typed asanywhen wrapping options in a Svelte 4derivedstore. The Svelte 5 rewrite removed that store-based API and the basic inline case now infersselectcorrectly, butcreateQuery/createInfiniteQuerywere still missing theNoInfer<TData>wrapper thatreact-query,preact-query, andvue-queryall use on their return types.This PR aligns svelte-query with the rest of the ecosystem so:
TDatais inferred from the input options only, never widened by a result-type annotation at the call site.selectinference is locked in instead of being silently overridden by contextual typing.Files changed
packages/svelte-query/src/createQuery.tsTDatainNoInferon all 3 overload return typespackages/svelte-query/src/createInfiniteQuery.tspackages/svelte-query/tests/createQuery/createQuery.test-d.tsselectdescribe block.changeset/svelte-query-no-infer-tdata.md@tanstack/svelte-queryVerification
pnpm exec nx run @tanstack/svelte-query:test:types— 0 errors across all TS versionspnpm exec nx run @tanstack/svelte-query:test:lib— all unit tests pass, coverage unchangedpnpm exec nx run @tanstack/svelte-query:test:eslint— cleanpnpm exec nx run @tanstack/query-core:test:types— no downstream regressionNoInfercauses the@ts-expect-errordirective to become unused (test fails) — confirmed manuallyGenerated by Ora Studio
Vibe coded by ousamabenyounes
Summary by CodeRabbit
selectfunctions has been improved to correctly determine the resulting data type, providing better type safety and consistency across TanStack query libraries.Vibe Coded by Ousama Ben Younes
Developed With Ora Studio (Claude Code)