Skip to content

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

Open
ousamabenyounes wants to merge 1 commit into
TanStack: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 into
TanStack: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

    • Improved type inference for queries using select functions so returned data types are inferred more accurately and consistently.
  • Tests

    • Added TypeScript compile-time tests to validate correct data-type inference for various select/use scenarios.
  • Chores

    • Added a release entry documenting the patch-level type-inference improvement.

Review Change Stack


Vibe Coded by Ousama Ben Younes
Developed With Ora Studio (Claude Code)

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 25, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 1e40aaf1-5c2a-4a9e-9006-3eb4fb7ab0a9

📥 Commits

Reviewing files that changed from the base of the PR and between 562030d and 0fcf5b7.

📒 Files selected for processing (1)
  • .changeset/svelte-query-no-infer-tdata.md
✅ Files skipped from review due to trivial changes (1)
  • .changeset/svelte-query-no-infer-tdata.md

📝 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, and adds a changeset and type tests validating select inference.

Changes

Svelte-query TData inference fix

Layer / 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.
Return-type updates
packages/svelte-query/src/createQuery.ts, packages/svelte-query/src/createInfiniteQuery.ts
Return types updated to CreateQueryResult<NoInfer<TData>, TError> / CreateInfiniteQueryResult<NoInfer<TData>, TError>; no runtime logic changes.
Type tests
packages/svelte-query/tests/createQuery/createQuery.test-d.ts
New TypeScript tests asserting data inference with select, including cases using derived stores and base queryOptions.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

  • TanStack/query#10593: Related discussion and changes around using TypeScript's intrinsic NoInfer for similar inference issues.

Suggested reviewers

  • TkDodo

Poem

A rabbit nudges Typescript's gate,
Wraps data tight so types behave,
With NoInfer tricks and tests in tow,
Selects resolve and typings grow,
Hooray — no more inference woe! 🐇✨

🚥 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 accurately describes the main change: wrapping TData in NoInfer on svelte-query return types to fix issue #7673 regarding select type inference.
Description check ✅ Passed The PR description comprehensively covers the changes, objectives, files modified, and verification steps performed, aligning with the template structure and providing detailed context.
Linked Issues check ✅ Passed The PR successfully addresses issue #7673 by wrapping TData in NoInfer across createQuery and createInfiniteQuery return types, aligning svelte-query with other adapters and preventing TData widening from result-type annotations.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing issue #7673: type wrapper updates in createQuery/createInfiniteQuery, corresponding type tests, and a changeset entry. No unrelated or extraneous modifications detected.

✏️ 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

…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>
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