Skip to content

Commit 5f82c4d

Browse files
committed
fix(query-core): restore NoInfer on persister's TQueryKey
Follow-up to #10510. That PR removed NoInfer from all three persister generics to fix TQueryFnData inference when the companion queryFn declares a parameter (#7842). Keeping NoInfer on TQueryKey preserves that fix while preventing the persister slot from widening TQueryKey inference. Without NoInfer on TQueryKey, the persister slot contributes to TQueryKey inference. When Register.queryKey is augmented to a narrowed constraint, TQueryKey widens to that constraint instead of the literal passed to queryKey. Wrappers that brand their return with DataTag<TQueryKey, ...> then produce a brand on the wider type, which a plain literal tuple can no longer satisfy in contravariant positions (vi.mocked(...).mockReturnValue, typed variable assignments, etc.). TQueryFnData still participates in inference, so #10510's positive and negative type tests continue to pass.
1 parent dd901ae commit 5f82c4d

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@tanstack/query-core': patch
3+
---
4+
5+
fix(query-core): wrap `persister`'s `TQueryKey` in `NoInfer` so that the `persister` slot no longer contributes to `TQueryKey` inference. Follow-up to #10510, which removed `NoInfer` on all three `persister` generics. Preserving `NoInfer<TQueryKey>` keeps that fix's benefit for `TQueryFnData` while preventing `TQueryKey` from widening to the augmented constraint when `Register.queryKey` is narrowed — which made `DataTag`-branded wrapper returns un-assignable in contravariant slots.

packages/query-core/src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ export interface QueryOptions<
246246
*/
247247
gcTime?: number
248248
queryFn?: QueryFunction<TQueryFnData, TQueryKey, TPageParam> | SkipToken
249-
persister?: QueryPersister<TQueryFnData, TQueryKey, TPageParam>
249+
persister?: QueryPersister<TQueryFnData, NoInfer<TQueryKey>, TPageParam>
250250
queryHash?: string
251251
queryKey?: TQueryKey
252252
queryKeyHashFn?: QueryKeyHashFunction<TQueryKey>

0 commit comments

Comments
 (0)