Commit d423168
fix(query-core): use built-in NoInfer for generic indexed-access types (#10593)
* fix(query-core): use built-in NoInfer to support generic indexed-access types
The local `NoInfer<T> = [T][T extends any ? 0 : never]` trick breaks down
when `T` is a generic indexed-access type such as `DataTypeToEntity[DT]`,
producing errors like "Type '[DataTypeToEntity[DT]]' is not assignable to
type 'DataTypeToEntity'".
Since the project already requires TypeScript >= 5.4, delegate the public
`NoInfer<T>` alias to TypeScript's built-in `NoInfer` (introduced in 5.4).
A small `noInfer.ts` helper exposes it as `IntrinsicNoInfer<T>` to avoid
the local-shadow recursion problem.
Vue's `setQueryData` implementation now forwards the `<TData>` generic to
`super.setQueryData<TData>(...)` so its declared `NoInfer<TData> | undefined`
return type stays satisfied under the stricter built-in `NoInfer`.
Fixes #9937
* test(react-query): move 'generic indexed access TData' describe out of 'initialData'
Block was nested inside `describe('initialData', ...)` but is unrelated
to initialData behavior. Lift it to sibling level under
`describe('useQuery', ...)` so test output groups it correctly.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* test(react-query): document implicit regression guard for generic indexed-access NoInfer
Per CodeRabbit nitpick: clarify that the `getLabel(props.dataType, data)` call
itself is the regression guard. With the previous hand-rolled NoInfer, this
call failed to type-check; with built-in NoInfer (TS 5.4+), it compiles.
An explicit `expectTypeOf(data).toEqualTypeOf<...>()` / `toMatchTypeOf<...>()`
cannot work here — vitest's type-relation checks reduce to
`Extends<NoInfer<T>, T>` which TS leaves unresolved under a generic
`TDataType extends DataType` constraint.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* refactor(query-core): drop NoInfer re-export, use built-in everywhere
Per @TkDodo's review: TypeScript's intrinsic NoInfer (TS ≥ 5.4) is the
canonical type, and the package already requires TS ≥ 5.4. Removing the
re-export sidesteps the self-shadowing issue entirely and avoids
encouraging consumers to import a duplicate.
---------
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-authored-by: Dominik Dorfmeister 🔮 <office@dorfmeister.cc>1 parent 5ff4f69 commit d423168
7 files changed
Lines changed: 57 additions & 17 deletions
File tree
- .changeset
- packages
- preact-query/src
- query-core/src
- react-query/src
- __tests__
- vue-query/src
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
3 | | - | |
4 | | - | |
5 | | - | |
6 | | - | |
7 | | - | |
| 2 | + | |
8 | 3 | | |
9 | 4 | | |
10 | 5 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
32 | | - | |
33 | 32 | | |
34 | 33 | | |
35 | 34 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
37 | | - | |
38 | | - | |
39 | 37 | | |
40 | 38 | | |
41 | 39 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
338 | 338 | | |
339 | 339 | | |
340 | 340 | | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
341 | 389 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
5 | | - | |
6 | | - | |
7 | | - | |
8 | | - | |
9 | | - | |
| 4 | + | |
10 | 5 | | |
11 | 6 | | |
12 | 7 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | | - | |
25 | 24 | | |
26 | 25 | | |
27 | 26 | | |
| |||
125 | 124 | | |
126 | 125 | | |
127 | 126 | | |
128 | | - | |
| 127 | + | |
129 | 128 | | |
130 | 129 | | |
131 | 130 | | |
| |||
0 commit comments