@@ -30,6 +30,9 @@ import type { HttpMethod, MediaType, PathsWithMethod, RequiredKeysOf } from "ope
3030type InferSelectReturnType < TData , TSelect > = TSelect extends ( data : TData ) => infer R ? R : TData ;
3131
3232type InitWithUnknowns < Init > = Init & { [ key : string ] : unknown } ;
33+ // Keep arbitrary fetch init fields while reserving options for React Query itself.
34+ type QueryInit < Init > = InitWithUnknowns < Init > & { [ Key in keyof UseQueryOptions ] ?: never } ;
35+ type InfiniteQueryInit < Init > = InitWithUnknowns < Init > & { [ Key in keyof UseInfiniteQueryOptions ] ?: never } ;
3336
3437export type QueryKey <
3538 Paths extends Record < string , Record < HttpMethod , { } > > ,
@@ -55,9 +58,7 @@ export type QueryOptionsFunction<Paths extends Record<string, Record<HttpMethod,
5558> (
5659 method : Method ,
5760 path : Path ,
58- ...[ init , options ] : RequiredKeysOf < Init > extends never
59- ? [ InitWithUnknowns < Init > ?, Options ?]
60- : [ InitWithUnknowns < Init > , Options ?]
61+ ...[ init , options ] : RequiredKeysOf < Init > extends never ? [ QueryInit < Init > ?, Options ?] : [ QueryInit < Init > , Options ?]
6162) => NoInfer <
6263 Omit <
6364 UseQueryOptions <
@@ -99,8 +100,8 @@ export type UseQueryMethod<Paths extends Record<string, Record<HttpMethod, {}>>,
99100 method : Method ,
100101 url : Path ,
101102 ...[ init , options , queryClient ] : RequiredKeysOf < Init > extends never
102- ? [ InitWithUnknowns < Init > ?, Options ?, QueryClient ?]
103- : [ InitWithUnknowns < Init > , Options ?, QueryClient ?]
103+ ? [ QueryInit < Init > ?, Options ?, QueryClient ?]
104+ : [ QueryInit < Init > , Options ?, QueryClient ?]
104105) => UseQueryResult < InferSelectReturnType < Response [ "data" ] , Options [ "select" ] > , Response [ "error" ] > ;
105106
106107export type UseInfiniteQueryMethod < Paths extends Record < string , Record < HttpMethod , { } > > , Media extends MediaType > = <
@@ -123,7 +124,7 @@ export type UseInfiniteQueryMethod<Paths extends Record<string, Record<HttpMetho
123124> (
124125 method : Method ,
125126 url : Path ,
126- init : InitWithUnknowns < Init > ,
127+ init : InfiniteQueryInit < Init > ,
127128 options : Options ,
128129 queryClient ?: QueryClient ,
129130) => UseInfiniteQueryResult <
@@ -149,8 +150,8 @@ export type UseSuspenseQueryMethod<Paths extends Record<string, Record<HttpMetho
149150 method : Method ,
150151 url : Path ,
151152 ...[ init , options , queryClient ] : RequiredKeysOf < Init > extends never
152- ? [ InitWithUnknowns < Init > ?, Options ?, QueryClient ?]
153- : [ InitWithUnknowns < Init > , Options ?, QueryClient ?]
153+ ? [ QueryInit < Init > ?, Options ?, QueryClient ?]
154+ : [ QueryInit < Init > , Options ?, QueryClient ?]
154155) => UseSuspenseQueryResult < InferSelectReturnType < Response [ "data" ] , Options [ "select" ] > , Response [ "error" ] > ;
155156
156157export type UseMutationMethod < Paths extends Record < string , Record < HttpMethod , { } > > , Media extends MediaType > = <
0 commit comments