From 5f82c4ddc90df087b7b4de106cbae58bcfdc9b47 Mon Sep 17 00:00:00 2001 From: neefrehman Date: Mon, 27 Apr 2026 17:43:14 +0100 Subject: [PATCH] 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 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. --- .changeset/fix-persister-query-key-infer.md | 5 +++++ packages/query-core/src/types.ts | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 .changeset/fix-persister-query-key-infer.md diff --git a/.changeset/fix-persister-query-key-infer.md b/.changeset/fix-persister-query-key-infer.md new file mode 100644 index 00000000000..e721d6dcfb9 --- /dev/null +++ b/.changeset/fix-persister-query-key-infer.md @@ -0,0 +1,5 @@ +--- +'@tanstack/query-core': patch +--- + +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` 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. diff --git a/packages/query-core/src/types.ts b/packages/query-core/src/types.ts index 6e26b02746a..dcd5f7e9e2e 100644 --- a/packages/query-core/src/types.ts +++ b/packages/query-core/src/types.ts @@ -246,7 +246,7 @@ export interface QueryOptions< */ gcTime?: number queryFn?: QueryFunction | SkipToken - persister?: QueryPersister + persister?: QueryPersister, TPageParam> queryHash?: string queryKey?: TQueryKey queryKeyHashFn?: QueryKeyHashFunction