fix(query-core): use built-in NoInfer for generic indexed-access types #10593
main fromrefs/pull/10593/head·merged by TkDodo View on GitHubSummary#
Fixes #9937.
Root cause#
The public NoInfer<T> exported from @tanstack/query-core is defined as the historical pre-TS-5.4 trick:
export type NoInfer<T> = [T][T extends any ? 0 : never]
When T is a generic indexed-access type (e.g. DataTypeToEntity[DT] inside a function generic over DT extends keyof DataTypeToEntity), TypeScript fails to recognize that NoInfer<DataTypeToEntity[DT]> and DataTypeToEntity[DT] are the same:
Argument of type 'NoInfer<DataTypeToEntity[DT]>' is not assignable to parameter of type 'DataTypeToEntity[DT]'.
Type '[DataTypeToEntity[DT]]' is not assignable to type 'DataTypeToEntity'.
The package already requires TypeScript ≥ 5.4 (lowest CI target is typescript@5.4), so the built-in intrinsic NoInfer is available everywhere it ships.
Fix#
- Add a tiny
packages/query-core/src/noInfer.tsthat re-exports the built-inNoInferunder anIntrinsicNoInfer<T>alias, sidestepping the self-shadowing problem when delegating from a same-named export. - Change
export type NoInfer<T>inpackages/query-core/src/types.tstoIntrinsicNoInfer<T>. - Update
packages/vue-query/src/queryClient.ts:super.setQueryData<TData>(...)forwards theTDatageneric explicitly so the stricter built-inNoInfer<TData>return type stays satisfied (previously theunknownreturned from the unparameterized call was passing only because the loose tuple-index trick masked it).
The public NoInfer export keeps the same identity, so no consumer-visible API change.
Verification#
Added type test in packages/react-query/src/__tests__/useQuery.test-d.tsx (generic indexed access TData) that mirrors the issue's repro: useQuery inside a function generic over <TDataType extends DataType> whose data is then forwarded to getLabel(_, data: DataTypeToEntity[TDataType]). Without the fix it errors with the exact [DataTypeToEntity[DT]] is not assignable message; with the fix it type-checks.
Local check matrix (all green):
pnpm exec nx run @tanstack/query-core:test:libpnpm exec nx run @tanstack/query-core:test:types(TS 5.4–6.0)pnpm exec nx run @tanstack/query-core:test:eslintpnpm exec nx run @tanstack/react-query:test:libpnpm exec nx run @tanstack/react-query:test:types(TS 5.4–6.0)pnpm exec nx run @tanstack/react-query:test:eslintpnpm exec nx run @tanstack/vue-query:test:libpnpm exec nx run @tanstack/vue-query:test:types(TS 5.4–6.0)pnpm exec nx run @tanstack/vue-query:test:eslintpnpm exec nx run @tanstack/{preact,solid,svelte,angular-query-experimental,query-persist-client-core}:test:types
Test plan#
- Unit + type tests pass on all supported TS versions
- Existing
TData should depend from only arguments, not the resultts-expect-error test (ensuresNoInferstill blocks reverse inference) keeps erroring - Changeset added (
patchfor@tanstack/query-coreand@tanstack/vue-query)
Generated by Ora Studio Vibe coded by ousamabenyounes
Summary by CodeRabbit#
Bug Fixes
- Replaced a custom type handling with TypeScript’s built-in NoInfer to fix assignability in generic/indexed-access contexts.
Tests
- Added TypeScript-only regression tests to verify generic inference and indexed-access behavior.
Chores
- Published a patch release and added a release note documenting the fix.
Generated by Ora Studio (with Claude Code) Vibe coded by Ben Younes Ousama
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: react-query
github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: vue-query
github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: query-core
View your CI Pipeline Execution ↗ for commit 4f7143d386b340de35da2a5ca2c46bff979aa151
Command Status Duration Result nx affected --targets=test:sherif,test:knip,tes...✅ Succeeded 4m 56s View ↗ nx run-many --target=build --exclude=examples/*...✅ Succeeded 1m 49s View ↗
☁️ Nx Cloud last updated this comment at
2026-05-22 19:08:45UTCMore templates
- @tanstack/query-example-angular-auto-refetching
- @tanstack/query-example-angular-basic
- @tanstack/query-example-angular-basic-persister
- @tanstack/query-example-angular-devtools-panel
- @tanstack/query-example-angular-infinite-query-with-max-pages
- @tanstack/query-example-angular-optimistic-updates
- @tanstack/query-example-angular-pagination
- @tanstack/query-example-angular-query-options-from-a-service
- @tanstack/query-example-angular-router
- @tanstack/query-example-angular-rxjs
- @tanstack/query-example-angular-simple
- @tanstack/query-example-lit-basic
- @tanstack/query-example-lit-pagination
- @tanstack/query-example-lit-ssr
- @tanstack/query-example-preact-simple
- @tanstack/query-example-react-algolia
- @tanstack/query-example-react-auto-refetching
- @tanstack/query-example-react-basic
- @tanstack/query-example-react-basic-graphql-request
- @tanstack/query-example-chat
- @tanstack/query-example-react-default-query-function
- @tanstack/query-example-react-devtools-panel
- @tanstack/query-example-eslint-legacy
- @tanstack/query-example-eslint-plugin-demo
- @tanstack/query-example-react-infinite-query-with-max-pages
- @tanstack/query-example-react-load-more-infinite-scroll
- @tanstack/query-example-react-nextjs
- @tanstack/query-example-react-nextjs-app-prefetching
- @tanstack/query-example-nextjs-suspense-streaming
- @tanstack/query-example-react-offline
- @tanstack/query-example-react-optimistic-updates-cache
- @tanstack/query-example-react-optimistic-updates-ui
- @tanstack/query-example-react-pagination
- @tanstack/query-example-react-playground
- @tanstack/query-example-react-prefetching
- @tanstack/query-example-react-react-native
- @tanstack/query-example-react-router
- @tanstack/query-example-react-rick-morty
- @tanstack/query-example-react-shadow-dom
- @tanstack/query-example-react-simple
- @tanstack/query-example-react-star-wars
- @tanstack/query-example-react-suspense
- @tanstack/query-example-solid-astro
- @tanstack/query-example-solid-basic
- @tanstack/query-example-solid-basic-graphql-request
- @tanstack/query-example-solid-default-query-function
- @tanstack/query-example-solid-offline
- @tanstack/query-example-solid-simple
- @tanstack/query-example-solid-start-streaming
- @tanstack/query-example-svelte-auto-refetching
- @tanstack/query-example-svelte-basic
- @tanstack/query-example-svelte-load-more-infinite-scroll
- @tanstack/query-example-svelte-optimistic-updates
- @tanstack/query-example-svelte-playground
- @tanstack/query-example-svelte-simple
- @tanstack/query-example-svelte-ssr
- @tanstack/query-example-svelte-star-wars
- @tanstack/query-example-vue-2.6-basic
- @tanstack/query-example-vue-2.7-basic
- @tanstack/query-example-vue-basic
- @tanstack/query-example-vue-dependent-queries
- @tanstack/query-example-vue-nuxt3
- @tanstack/query-example-vue-persister
- @tanstack/query-example-vue-simple
@tanstack/angular-query-experimental
npm i https://pkg.pr.new/@tanstack/angular-query-experimental@10593@tanstack/eslint-plugin-query
npm i https://pkg.pr.new/@tanstack/eslint-plugin-query@10593@tanstack/lit-query
npm i https://pkg.pr.new/@tanstack/lit-query@10593@tanstack/preact-query
npm i https://pkg.pr.new/@tanstack/preact-query@10593@tanstack/preact-query-devtools
npm i https://pkg.pr.new/@tanstack/preact-query-devtools@10593@tanstack/preact-query-persist-client
npm i https://pkg.pr.new/@tanstack/preact-query-persist-client@10593@tanstack/query-async-storage-persister
npm i https://pkg.pr.new/@tanstack/query-async-storage-persister@10593@tanstack/query-broadcast-client-experimental
npm i https://pkg.pr.new/@tanstack/query-broadcast-client-experimental@10593@tanstack/query-core
npm i https://pkg.pr.new/@tanstack/query-core@10593@tanstack/query-devtools
npm i https://pkg.pr.new/@tanstack/query-devtools@10593@tanstack/query-persist-client-core
npm i https://pkg.pr.new/@tanstack/query-persist-client-core@10593@tanstack/query-sync-storage-persister
npm i https://pkg.pr.new/@tanstack/query-sync-storage-persister@10593@tanstack/react-query
npm i https://pkg.pr.new/@tanstack/react-query@10593@tanstack/react-query-devtools
npm i https://pkg.pr.new/@tanstack/react-query-devtools@10593@tanstack/react-query-next-experimental
npm i https://pkg.pr.new/@tanstack/react-query-next-experimental@10593@tanstack/react-query-persist-client
npm i https://pkg.pr.new/@tanstack/react-query-persist-client@10593@tanstack/solid-query
npm i https://pkg.pr.new/@tanstack/solid-query@10593@tanstack/solid-query-devtools
npm i https://pkg.pr.new/@tanstack/solid-query-devtools@10593@tanstack/solid-query-persist-client
npm i https://pkg.pr.new/@tanstack/solid-query-persist-client@10593@tanstack/svelte-query
npm i https://pkg.pr.new/@tanstack/svelte-query@10593@tanstack/svelte-query-devtools
npm i https://pkg.pr.new/@tanstack/svelte-query-devtools@10593@tanstack/svelte-query-persist-client
npm i https://pkg.pr.new/@tanstack/svelte-query-persist-client@10593@tanstack/vue-query
npm i https://pkg.pr.new/@tanstack/vue-query@10593@tanstack/vue-query-devtools
npm i https://pkg.pr.new/@tanstack/vue-query-devtools@10593commit:
4f7143dActionable comments posted: 1
🧹 Nitpick comments (1)
packages/react-query/src/__tests__/useQuery.test-d.tsx (1)
382-382: Optional: assert the test scenario more directly.expectTypeOf(Test).toBeFunction()is essentially a no-op that exists to keepTestreferenced. Since the regression you're guarding against is purely compile-time (the body ofTestfailing to type-check), theitblock compiling is the real assertion. You could either drop the assertion (the function's existence already guards the regression) or assert something more meaningful, e.g. that thedatainsideTest's body is assignable toDataTypeToEntity[TDataType] | undefined. Not blocking.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/react-query/src/__tests__/useQuery.test-d.tsx` at line 382, The current test only references Test via expectTypeOf(Test).toBeFunction(), which is a weak/no-op; replace or strengthen it by asserting the compile-time assignment you care about: inside the test suite replace the expectTypeOf(Test).toBeFunction() line with a type assertion that the local variable used in Test (named data) is assignable to DataTypeToEntity[TDataType] | undefined (or drop the assertion entirely and rely on the test body compiling), e.g. use TypeScript's expectType or similar utility to assert data is of type DataTypeToEntity[TDataType] | undefined so the regression is guarded by an explicit compile-time check of data's type.🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed. Inline comments: In `@packages/react-query/src/__tests__/useQuery.test-d.tsx`: - Around line 341-384: The new describe block describe('generic indexed access TData', …) is incorrectly nested inside describe('initialData', …); move the entire describe('generic indexed access TData', ...) block so it is a sibling of describe('initialData') under the top-level describe('useQuery', …) (i.e., close the initialData describe before this new describe). Concretely, relocate the describe block (the entire chunk containing enum DataType, DataTypeToEntity, getData, getLabel, function Test, and the expectTypeOf assertion) to be placed after the closing brace of describe('initialData', …) so it sits at the same level as initialData and not inside it. --- Nitpick comments: In `@packages/react-query/src/__tests__/useQuery.test-d.tsx`: - Line 382: The current test only references Test via expectTypeOf(Test).toBeFunction(), which is a weak/no-op; replace or strengthen it by asserting the compile-time assignment you care about: inside the test suite replace the expectTypeOf(Test).toBeFunction() line with a type assertion that the local variable used in Test (named data) is assignable to DataTypeToEntity[TDataType] | undefined (or drop the assertion entirely and rely on the test body compiling), e.g. use TypeScript's expectType or similar utility to assert data is of type DataTypeToEntity[TDataType] | undefined so the regression is guarded by an explicit compile-time check of data's type.🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID:
2268aa9f-4f19-4ae2-8111-03e4fb810e30📥 Commits
Reviewing files that changed from the base of the PR and between 51ef23f46b23f9f7fd858386e42bfbb3adb5e49d and e9172ef8f4d18c117d9a11307c56e677e9f875d4.
📒 Files selected for processing (5)
.changeset/query-core-noinfer-builtin.mdpackages/query-core/src/noInfer.tspackages/query-core/src/types.tspackages/react-query/src/__tests__/useQuery.test-d.tsxpackages/vue-query/src/queryClient.ts
@@ -339,0 +364,21 @@364+ Promise.resolve({} as DataTypeToEntity[TDataType])365+366+ const getLabel = <TDataType extends DataType>(367+ _dataType: TDataType,368+ _data: DataTypeToEntity[TDataType],369+ ) => 'test'370+371+ function Test<TDataType extends DataType>(props: {372+ dataType: TDataType373+ }) {374+ const { data } = useQuery({375+ queryKey: ['test'],376+ queryFn: () => getData(props.dataType),377+ })378+379+ return data ? getLabel(props.dataType, data) : null380+ }381+382+ expectTypeOf(Test).toBeFunction()383+ })384+ })⚠️ Potential issue | 🟡 Minor
Wrong
describenesting — the new block lives insidedescribe('initialData', …).Looking at the closing braces, the new
describe('generic indexed access TData', …)is nested inside thedescribe('initialData', …)block (which closes at line 385). This test is unrelated toinitialDataand should sit at the same level asdescribe('initialData', …)under the top-leveldescribe('useQuery', …). Otherwise it shows up under "initialData → generic indexed access TData" in test output, which is misleading for future contributors and CI logs.♻️ Proposed structural fix
Move the block out of
initialData. Concretely, swap the order of})at lines 384 and 385 so the newdescribecloses theinitialDatagroup first, then sits at theuseQuerylevel:}) }) + }) + + describe('generic indexed access TData', () => { + // https://github.com/TanStack/query/issues/9937 + it('should be assignable back to its source indexed type when passed to a generic function parameter', () => { + // ... existing body ... + }) + }) })(i.e., relocate lines 341–384 to after line 385 instead of before it.)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/react-query/src/__tests__/useQuery.test-d.tsx` around lines 341 - 384, The new describe block describe('generic indexed access TData', …) is incorrectly nested inside describe('initialData', …); move the entire describe('generic indexed access TData', ...) block so it is a sibling of describe('initialData') under the top-level describe('useQuery', …) (i.e., close the initialData describe before this new describe). Concretely, relocate the describe block (the entire chunk containing enum DataType, DataTypeToEntity, getData, getLabel, function Test, and the expectTypeOf assertion) to be placed after the closing brace of describe('initialData', …) so it sits at the same level as initialData and not inside it.✅ Addressed in commit d942386
Thanks @coderabbitai — addressed in d942386ce. Lifted
describe('generic indexed access TData', ...)out ofdescribe('initialData', ...)so it now sits atdescribe('useQuery', ...)level. Test output groups it correctly. Verified withpnpm exec nx run @tanstack/react-query:test:types,test:libandtest:eslint— all green.Tip
For best results, initiate chat on the files or code changes.
@ousamabenyounes: Thanks for the update — moving thedescribe('generic indexed access TData', ...)block to the top-leveldescribe('useQuery', ...)scope is exactly the right placement, and it's great that the full type/lib/eslint test matrix came back green. Appreciate the thorough verification! 🎉
🧠 Learnings used
Learnt from: sukvvon Repo: TanStack/query PR: 9892 File: packages/solid-query-persist-client/src/__tests__/PersistQueryClientProvider.test.tsx:331-335 Timestamp: 2025-11-22T09:06:05.219Z Learning: In TanStack/query test files, when a queryFn contains side effects (e.g., setting flags for test verification), prefer async/await syntax for clarity; when there are no side effects, prefer the .then() pattern for conciseness.
Learnt from: ousamabenyounes Repo: TanStack/query PR: 0 File: :0-0 Timestamp: 2026-04-26T07:26:42.601Z Learning: In `packages/solid-query/src/useQueries.ts` (TanStack/query), the per-query proxy / `createResource` path iterates the reactive `state` store as an array (e.g., `queryResults.map` at line 256). When `combine` returns a non-array object shape, this throws `TypeError: queryResults.map is not a function` unconditionally at runtime. The type-level fix in PR `#10577` (relaxing `TCombinedResult extends object`) covers only the TypeScript constraint; the runtime resource-path rework to support non-array `combine` returns is explicitly deferred and tracked in issue `#7522`.
Learnt from: byungsker Repo: TanStack/query PR: 10465 File: packages/vue-query/src/__tests__/queryOptions.test-d.ts:292-300 Timestamp: 2026-04-13T15:15:51.168Z Learning: In `packages/vue-query/src/queryOptions.ts`, the predicate form of `enabled` — i.e., `(query) => boolean` — is not supported by `queryOptions` (throws a TypeScript error). This is a pre-existing limitation that exists even on the main branch, unrelated to any specific PR. It is distinct from the simple getter form `() => boolean` which is supported. Predicate support in `queryOptions` would require a separate feature implementation.
Learnt from: ousamabenyounes Repo: TanStack/query PR: 0 File: :0-0 Timestamp: 2026-04-25T22:35:09.256Z Learning: In `packages/vue-query/src/useBaseQuery.ts`, the `suspense` method in `UseBaseQueryReturnType` should be declared **outside** the distributive conditional type and typed as `Promise<TResult>` (not pinned to `Promise<QueryObserverResult<TData, TError>>`). This preserves the parameterized observer shape for callers using specialized variants like `DefinedQueryObserverResult` (non-undefined `data`) and `InfiniteQueryObserverResult` (`fetchNextPage`/`hasNextPage`/`data.pages`), and aligns with the runtime value returned by `observer.fetchOptimistic()`.
Learnt from: oscartbeaumont Repo: TanStack/query PR: 9564 File: packages/solid-query-devtools/src/production.tsx:2-3 Timestamp: 2025-08-19T03:18:18.303Z Learning: In the solid-query-devtools package, the codebase uses a pattern of type-only default imports combined with typeof for component type annotations (e.g., `import type SolidQueryDevtoolsComp from './devtools'` followed by `typeof SolidQueryDevtoolsComp`). This pattern is consistently used across index.tsx and production.tsx files, and the maintainers prefer consistency over changing this approach.
If you found this review helpful, would you consider giving us a shout-out on X?
Thank you for using CodeRabbit!
Thanks @coderabbitai — addressed the optional nit in 24c74b9ba. Tried strengthening with both
expectTypeOf(data).toEqualTypeOf<DataTypeToEntity[TDataType] | undefined>()and.toMatchTypeOf<...>()— both fail to compile because vitest's type-relation checks reduce toExtends<NoInfer<T>, T>which TS leaves unresolved under the genericTDataType extends DataTypeconstraint.Per your suggestion ("the function's existence already guards the regression"), kept the implicit assertion (
getLabel(props.dataType, data)must compile) and added a short comment documenting the intent so future readers don't mistake it for a no-op.Type tests + lint all green locally.
Tip
For best results, initiate chat on the files or code changes.
@ousamabenyounes: That's a solid explanation — theExtends<NoInfer<T>, T>resolution failure underTDataType extends DataTypeis a known limitation of vitest's type helpers in generic contexts, and it meanstoEqualTypeOf/toMatchTypeOfare genuinely off the table here without a concrete instantiation. The implicit compile-time assertion (getLabel(props.dataType, data)must compile, plus the explanatory comment) is the right call: it's exactly as strong as anything vitest can offer in this scenario, and future maintainers will now understand why it's not a dead-code no-op.🐇 ~ inspecting types in a generic burrow ~ (\ /) ( •.•) NoInfer[T]? (> 🔍 <) TS says "¯\_(ツ)_/¯" — but the compile passes, and that's enough.
✏️ Learnings added
Learnt from: ousamabenyounes URL: https://github.com/TanStack/query/pull/10593 Timestamp: 2026-04-26T09:14:54.328Z Learning: In `packages/react-query/src/__tests__/useQuery.test-d.tsx` (TanStack/query), when writing type tests for `useQuery` with a generic indexed-access `TData` (e.g., `DataTypeToEntity[TDataType]`), `expectTypeOf(data).toEqualTypeOf<DataTypeToEntity[TDataType] | undefined>()` and `.toMatchTypeOf<...>()` both fail to compile because vitest's type-relation helpers reduce to `Extends<NoInfer<T>, T>`, which TypeScript leaves unresolved under the `TDataType extends DataType` generic constraint. The correct approach is to rely on the implicit compile-time assertion — i.e., passing `data` into a function that accepts `DataTypeToEntity[TDataType]` (such as `getLabel(props.dataType, data)`) — and document the intent with a comment so future readers do not mistake it for a no-op.Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.
🧠 Learnings used
Learnt from: ousamabenyounes Repo: TanStack/query PR: 0 File: :0-0 Timestamp: 2026-04-26T07:26:42.601Z Learning: In `packages/solid-query/src/useQueries.ts` (TanStack/query), the per-query proxy / `createResource` path iterates the reactive `state` store as an array (e.g., `queryResults.map` at line 256). When `combine` returns a non-array object shape, this throws `TypeError: queryResults.map is not a function` unconditionally at runtime. The type-level fix in PR `#10577` (relaxing `TCombinedResult extends object`) covers only the TypeScript constraint; the runtime resource-path rework to support non-array `combine` returns is explicitly deferred and tracked in issue `#7522`.
Learnt from: ousamabenyounes Repo: TanStack/query PR: 0 File: :0-0 Timestamp: 2026-04-25T22:35:09.256Z Learning: In `packages/vue-query/src/useBaseQuery.ts`, the `suspense` method in `UseBaseQueryReturnType` should be declared **outside** the distributive conditional type and typed as `Promise<TResult>` (not pinned to `Promise<QueryObserverResult<TData, TError>>`). This preserves the parameterized observer shape for callers using specialized variants like `DefinedQueryObserverResult` (non-undefined `data`) and `InfiniteQueryObserverResult` (`fetchNextPage`/`hasNextPage`/`data.pages`), and aligns with the runtime value returned by `observer.fetchOptimistic()`.
Learnt from: sukvvon Repo: TanStack/query PR: 9892 File: packages/solid-query-persist-client/src/__tests__/PersistQueryClientProvider.test.tsx:331-335 Timestamp: 2025-11-22T09:06:05.219Z Learning: In TanStack/query test files, when a queryFn contains side effects (e.g., setting flags for test verification), prefer async/await syntax for clarity; when there are no side effects, prefer the .then() pattern for conciseness.
Learnt from: oscartbeaumont Repo: TanStack/query PR: 9564 File: packages/solid-query-devtools/src/production.tsx:2-3 Timestamp: 2025-08-19T03:18:18.303Z Learning: In the solid-query-devtools package, the codebase uses a pattern of type-only default imports combined with typeof for component type annotations (e.g., `import type SolidQueryDevtoolsComp from './devtools'` followed by `typeof SolidQueryDevtoolsComp`). This pattern is consistently used across index.tsx and production.tsx files, and the maintainers prefer consistency over changing this approach.
Learnt from: byungsker Repo: TanStack/query PR: 10465 File: packages/vue-query/src/__tests__/queryOptions.test-d.ts:292-300 Timestamp: 2026-04-13T15:15:51.168Z Learning: In `packages/vue-query/src/queryOptions.ts`, the predicate form of `enabled` — i.e., `(query) => boolean` — is not supported by `queryOptions` (throws a TypeScript error). This is a pre-existing limitation that exists even on the main branch, unrelated to any specific PR. It is distinct from the simple getter form `() => boolean` which is supported. Predicate support in `queryOptions` would require a separate feature implementation.TkDodo reviewed
OutdatedResolvedby TkDodo@@ -34,4 +35,4 @@3435 : TTargetA[AKey]3536 }363737-export type NoInfer<T> = [T][T extends any ? 0 : never]38+export type NoInfer<T> = IntrinsicNoInfer<T>I’m also fine with just removing this type altogether? I know it is exported but people shouldn’t really use our
NoInfertype if it exists intrinsically anyways!@TkDodo done — dropped the public
NoInfer<T>re-export entirely in 011141dc0 and let consumers + internals use TypeScript's intrinsicNoInferdirectly. Also removed the./noInfer.tsshim since it's no longer needed. Type tests + lint + lib tests pass on TS 5.4–6.0 across query-core, react-query, vue-query, preact-query, solid-query, svelte-query, angular-query-experimental, query-persist-client-core.github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: preact-query
TkDodo approved these changes
TkDodo merged thisd423168
TkDodo closed this
Tip
For best results, initiate chat on the files or code changes.
@TkDodoThanks for the explanation and update. KeepinggetLabel(props.dataType, data)preserves the compile-time check for this regression. The comment explains whyexpectTypeOfis unsuitable in this generic context.That addresses the optional nit. Thanks for confirming that type tests and lint pass locally.
You are interacting with an AI system.
Tip
For best results, initiate chat on the files or code changes.
@TkDodoThanks for the update. Movingdescribe('generic indexed access TData', ...)to the top-leveldescribe('useQuery', ...)addresses the test-grouping concern. Thanks for confirming that the type, library, and ESLint tests pass.You are interacting with an AI system.
Sign in to join this conversation.
Note
Reviews paused#
It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the
reviews.auto_review.auto_pause_after_reviewed_commitssetting.Use the following commands to manage reviews:
@coderabbitai resumeto resume automatic reviews.@coderabbitai reviewto trigger a single review.Use the checkboxes below for quick actions:
📝 Walkthrough
Walkthrough#
Removes a custom
NoInfer<T>export from@tanstack/query-core, stripsNoInferfrom type-only imports across packages, adds an explicit generic onsuper.setQueryData<TData>(...)in Vue, adds a TypeScript regression test for indexed-access generics, and creates a changeset entry.Changes#
NoInfer removal and propagation
packages/query-core/src/types.tsNoInfer<T>type alias from core types.packages/query-core/src/queryClient.tsNoInferfrom./typestype imports used by the core query client.packages/react-query/src/useQuery.ts,packages/preact-query/src/useQuery.tsNoInferfrom import lists.packages/vue-query/src/queryClient.tssuper.setQueryData<TData>(...)with explicitTData; removed unusedNoInferimport.packages/react-query/src/__tests__/useQuery.test-d.tsxuseQuerypreserves indexed-access genericTDatainference..changeset/query-core-noinfer-builtin.mdNoInfer(TS ≥ 5.4), referencing issue#9937.Estimated code review effort#
🎯 3 (Moderate) | ⏱️ ~25 minutes
Poem#
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)#
✅ Passed checks (4 passed)
#9937, matching the template requirements.#9937by replacing the custom NoInfer tuple-index implementation with TypeScript's intrinsic NoInfer, fixing the generic indexed-access type assignment error and restoring code ergonomics.✨ 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.
❤️ Share