Skip to content

fix(svelte-query): wrap TData in NoInfer on query return types (#7673)#10578

Open
ousamabenyounes wants to merge 1 commit intoTanStack:mainfrom
ousamabenyounes:fix/issue-7673
Open

fix(svelte-query): wrap TData in NoInfer on query return types (#7673)#10578
ousamabenyounes wants to merge 1 commit intoTanStack:mainfrom
ousamabenyounes:fix/issue-7673

Conversation

@ousamabenyounes
Copy link
Copy Markdown
Contributor

@ousamabenyounes ousamabenyounes commented Apr 25, 2026

Summary

Fixes #7673.

The original report showed select's data parameter typed as any when wrapping options in a Svelte 4 derived store. The Svelte 5 rewrite removed that store-based API and the basic inline case now infers select correctly, but createQuery / createInfiniteQuery were still missing the NoInfer<TData> wrapper that react-query, preact-query, and vue-query all use on their return types.

This PR aligns svelte-query with the rest of the ecosystem so:

  • TData is inferred from the input options only, never widened by a result-type annotation at the call site.
  • select inference is locked in instead of being silently overridden by contextual typing.

Files changed

File Change
packages/svelte-query/src/createQuery.ts Wrap TData in NoInfer on all 3 overload return types
packages/svelte-query/src/createInfiniteQuery.ts Same wrapper on the single return type
packages/svelte-query/tests/createQuery/createQuery.test-d.ts 3 new type tests under a select describe block
.changeset/svelte-query-no-infer-tdata.md Patch changeset for @tanstack/svelte-query

Verification

  • pnpm exec nx run @tanstack/svelte-query:test:types — 0 errors across all TS versions
  • pnpm exec nx run @tanstack/svelte-query:test:lib — all unit tests pass, coverage unchanged
  • pnpm exec nx run @tanstack/svelte-query:test:eslint — clean
  • pnpm exec nx run @tanstack/query-core:test:types — no downstream regression
  • New negative test: removing NoInfer causes the @ts-expect-error directive to become unused (test fails) — confirmed manually
  • Pre-existing svelte-query type tests untouched

Generated by Ora Studio
Vibe coded by ousamabenyounes

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced type inference for select functions – Type inference in queries with select functions 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)

…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>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 25, 2026

📝 Walkthrough

Walkthrough

The PR updates svelte-query's createQuery and createInfiniteQuery to wrap their TData return types in NoInfer, ensuring type inference derives from input options rather than result-type annotations, improving select function type consistency.

Changes

Cohort / File(s) Summary
Changeset Metadata
.changeset/svelte-query-no-infer-tdata.md
Patch-level changelog entry documenting TData wrapping in NoInfer for improved type inference with select functions.
Type Declaration Updates
packages/svelte-query/src/createQuery.ts, packages/svelte-query/src/createInfiniteQuery.ts
Both files updated to wrap TData in NoInfer<TData> in their return types, aligning with react-query, preact-query, and vue-query patterns. No runtime logic changes.
Type Test Coverage
packages/svelte-query/tests/createQuery/createQuery.test-d.ts
New TypeScript type assertions validate that data type is correctly inferred when select is provided, including scenarios with derived stores and queryOptions.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

A rabbit hops through type inference lanes,
With NoInfer magic, no more broken chains,
select now whispers its truths so clear,
From input, not output, the types appear! 🐰✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: wrapping TData in NoInfer on svelte-query return types, fixing issue #7673.
Linked Issues check ✅ Passed The PR fully addresses issue #7673 by wrapping TData in NoInfer on createQuery and createInfiniteQuery return types, resolving the select inference bug when using Svelte stores.
Out of Scope Changes check ✅ Passed All changes are directly scoped to the linked issue: type wrapper updates, type tests, and a patch changeset for @tanstack/svelte-query with no unrelated modifications.
Description check ✅ Passed The PR description comprehensively covers all required template sections with clear problem statement, solution details, files changed, and verification results.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

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

@nx-cloud
Copy link
Copy Markdown

nx-cloud Bot commented Apr 25, 2026

View your CI Pipeline Execution ↗ for commit 562030d

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

☁️ Nx Cloud last updated this comment at 2026-04-25 10:54:59 UTC

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Apr 25, 2026

More templates

@tanstack/angular-query-experimental

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

@tanstack/eslint-plugin-query

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

@tanstack/preact-query

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

@tanstack/preact-query-devtools

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

@tanstack/preact-query-persist-client

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

@tanstack/query-async-storage-persister

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

@tanstack/query-broadcast-client-experimental

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

@tanstack/query-core

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

@tanstack/query-devtools

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

@tanstack/query-persist-client-core

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

@tanstack/query-sync-storage-persister

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

@tanstack/react-query

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

@tanstack/react-query-devtools

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

@tanstack/react-query-next-experimental

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

@tanstack/react-query-persist-client

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

@tanstack/solid-query

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

@tanstack/solid-query-devtools

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

@tanstack/solid-query-persist-client

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

@tanstack/svelte-query

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

@tanstack/svelte-query-devtools

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

@tanstack/svelte-query-persist-client

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

@tanstack/vue-query

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

@tanstack/vue-query-devtools

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

commit: 562030d

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Svelte: passing a store to createQuery breaks types when using select

1 participant