@@ -35,8 +35,7 @@ import { type BuilderOptions, BuilderPaginationOptions, mergeBuilderOptions, mer
3535import type { BuilderConfig , BuilderFlags , BuilderQueriesResult , HasClient , HasPagination , IsBound } from './types' ;
3636import { areKeysEqual , assertBound , getRandomKey , mergeMutationOptions , mergeVars } from './utils' ;
3737
38- type AnyBuilder < TFlags extends BuilderFlags > = QueryBuilderFrozen < any , any , any , any , any , TFlags > ;
39- type IsBoundThis < TFlags extends BuilderFlags > = IsBound < TFlags , AnyBuilder < TFlags > > ;
38+ type IsBoundThis < TFlags extends BuilderFlags , TB extends QueryBuilderFrozen < any , any , any , any , any , TFlags > > = IsBound < TFlags , TB > ;
4039
4140type UseQueriesArgs < TVars , TData , TError , TKey extends unknown [ ] > = [
4241 queries : {
@@ -113,7 +112,7 @@ export class QueryBuilderFrozen<
113112 //#region Query
114113
115114 getQueryFn (
116- this : IsBoundThis < TFlags > ,
115+ this : IsBoundThis < TFlags , this > ,
117116 operationType : 'query' | 'queries' | 'infiniteQuery' = 'query' ,
118117 ) : QueryFunction < TData , TKey , Partial < TVars > > {
119118 assertBound ( this ) ;
@@ -130,21 +129,21 @@ export class QueryBuilderFrozen<
130129 } ;
131130 }
132131
133- getQueryKeyHashFn ( this : IsBoundThis < TFlags > ) : ( key : TKey ) => string {
132+ getQueryKeyHashFn ( this : IsBoundThis < TFlags , this > ) : ( key : TKey ) => string {
134133 assertBound ( this ) ;
135134 return ( key ) => {
136135 const sanitized = this . config . queryKeySanitizer ? this . config . queryKeySanitizer ( key ) : key ;
137136 return hashKey ( sanitized ) ;
138137 } ;
139138 }
140139
141- getQueryKey ( this : IsBoundThis < TFlags > , vars : TVars ) : DataTag < TKey , TData , TError > {
140+ getQueryKey ( this : IsBoundThis < TFlags , this > , vars : TVars ) : DataTag < TKey , TData , TError > {
142141 assertBound ( this ) ;
143142 return [ this . preprocessVars ( this . mergeVars ( [ this . config . vars , vars as TODO ] ) ) ] as DataTag < TKey , TData , TError > ;
144143 }
145144
146145 getQueryOptions (
147- this : IsBoundThis < TFlags > ,
146+ this : IsBoundThis < TFlags , this > ,
148147 vars : TVars ,
149148 opts ?: BuilderOptions < TVars , TData , TError , TKey > ,
150149 operationType ?: 'query' | 'queries' | 'infiniteQuery' ,
@@ -162,26 +161,26 @@ export class QueryBuilderFrozen<
162161 ] ) as TODO ;
163162 }
164163
165- useQuery ( this : IsBoundThis < TFlags > , vars : TVars , opts ?: BuilderOptions < TVars , TData , TError , TKey > ) : UseQueryResult < TData , TError > {
164+ useQuery ( this : IsBoundThis < TFlags , this > , vars : TVars , opts ?: BuilderOptions < TVars , TData , TError , TKey > ) : UseQueryResult < TData , TError > {
166165 assertBound ( this ) ;
167166 return useQuery ( this . getQueryOptions ( vars , opts ) , this . config . queryClient ) ;
168167 }
169168
170169 useSuspenseQuery (
171- this : IsBoundThis < TFlags > ,
170+ this : IsBoundThis < TFlags , this > ,
172171 vars : TVars ,
173172 opts ?: BuilderOptions < TVars , TData , TError , TKey > ,
174173 ) : UseSuspenseQueryResult < TData , TError > {
175174 assertBound ( this ) ;
176175 return useSuspenseQuery ( this . getQueryOptions ( vars , opts ) , this . config . queryClient ) ;
177176 }
178177
179- usePrefetchQuery ( this : IsBoundThis < TFlags > , vars : TVars , opts ?: BuilderOptions < TVars , TData , TError , TKey > ) : void {
178+ usePrefetchQuery ( this : IsBoundThis < TFlags , this > , vars : TVars , opts ?: BuilderOptions < TVars , TData , TError , TKey > ) : void {
180179 assertBound ( this ) ;
181180 usePrefetchQuery ( this . getQueryOptions ( vars , opts ) , this . config . queryClient ) ;
182181 }
183182
184- useIsFetching ( this : IsBoundThis < TFlags > , vars : TVars , filters ?: QueryFilters ) : number {
183+ useIsFetching ( this : IsBoundThis < TFlags , this > , vars : TVars , filters ?: QueryFilters ) : number {
185184 assertBound ( this ) ;
186185 return useIsFetching ( { queryKey : this . getQueryKey ( vars ) , ...filters } , this . config . queryClient ) ;
187186 }
@@ -191,7 +190,7 @@ export class QueryBuilderFrozen<
191190 //#region Queries
192191
193192 private useQueriesInternal (
194- this : IsBoundThis < TFlags > ,
193+ this : IsBoundThis < TFlags , this > ,
195194 useHook : typeof useQueries | typeof useSuspenseQueries ,
196195 ...[ queries , sharedVars , sharedOpts ] : UseQueriesArgs < TVars , TData , TError , TKey >
197196 ) : BuilderQueriesResult < TVars , TData , TError , TKey > {
@@ -219,15 +218,15 @@ export class QueryBuilderFrozen<
219218 }
220219
221220 useQueries (
222- this : IsBoundThis < TFlags > ,
221+ this : IsBoundThis < TFlags , this > ,
223222 ...args : UseQueriesArgs < TVars , TData , TError , TKey >
224223 ) : BuilderQueriesResult < TVars , TData , TError , TKey > {
225224 assertBound ( this ) ;
226225 return this . useQueriesInternal ( useQueries , ...args ) ;
227226 }
228227
229228 useSuspenseQueries (
230- this : IsBoundThis < TFlags > ,
229+ this : IsBoundThis < TFlags , this > ,
231230 ...args : UseQueriesArgs < TVars , TData , TError , TKey >
232231 ) : BuilderQueriesResult < TVars , TData , TError , TKey > {
233232 assertBound ( this ) ;
@@ -241,7 +240,7 @@ export class QueryBuilderFrozen<
241240 declare getInfiniteQueryOptions : HasPagination <
242241 TFlags ,
243242 (
244- this : IsBoundThis < TFlags > ,
243+ this : IsBoundThis < TFlags , this > ,
245244 vars : TVars ,
246245 opts ?: Partial < BuilderPaginationOptions < TVars , TData , TError , TKey > > ,
247246 ) => WithRequired < BuilderPaginationOptions < TVars , TData , TError , TKey > , 'queryFn' | 'queryKey' | 'initialPageParam' >
@@ -250,21 +249,21 @@ export class QueryBuilderFrozen<
250249 declare useInfiniteQuery : HasPagination <
251250 TFlags ,
252251 (
253- this : IsBoundThis < TFlags > ,
252+ this : IsBoundThis < TFlags , this > ,
254253 vars : TVars ,
255254 opts ?: Partial < BuilderPaginationOptions < TVars , TData , TError , TKey > > ,
256255 ) => UseInfiniteQueryResult < InfiniteData < TData , Partial < TVars > > , TError >
257256 > ;
258257
259258 declare usePrefetchInfiniteQuery : HasPagination <
260259 TFlags ,
261- ( this : IsBoundThis < TFlags > , vars : TVars , opts ?: Partial < BuilderPaginationOptions < TVars , TData , TError , TKey > > ) => void
260+ ( this : IsBoundThis < TFlags , this > , vars : TVars , opts ?: Partial < BuilderPaginationOptions < TVars , TData , TError , TKey > > ) => void
262261 > ;
263262
264263 declare useSuspenseInfiniteQuery : HasPagination <
265264 TFlags ,
266265 (
267- this : IsBoundThis < TFlags > ,
266+ this : IsBoundThis < TFlags , this > ,
268267 vars : TVars ,
269268 opts ?: Partial < BuilderPaginationOptions < TVars , TData , TError , TKey > > ,
270269 ) => UseSuspenseInfiniteQueryResult < InfiniteData < TData , Partial < TVars > > , TError >
@@ -274,7 +273,7 @@ export class QueryBuilderFrozen<
274273
275274 //#region Mutation
276275
277- getMutationFn ( this : IsBoundThis < TFlags > , queryClient : QueryClient , meta ?: any ) : MutationFunction < TData , TVars > {
276+ getMutationFn ( this : IsBoundThis < TFlags , this > , queryClient : QueryClient , meta ?: any ) : MutationFunction < TData , TVars > {
278277 assertBound ( this ) ;
279278
280279 return async ( vars ) => {
@@ -291,7 +290,7 @@ export class QueryBuilderFrozen<
291290 }
292291
293292 #randomKey?: string ;
294- getMutationKey ( this : IsBoundThis < TFlags > ) : MutationKey {
293+ getMutationKey ( this : IsBoundThis < TFlags , this > ) : MutationKey {
295294 assertBound ( this ) ;
296295
297296 if ( this . config . options ?. mutationKey ) return this . config . options . mutationKey ;
@@ -302,7 +301,7 @@ export class QueryBuilderFrozen<
302301 }
303302
304303 getMutationOptions (
305- this : IsBoundThis < TFlags > ,
304+ this : IsBoundThis < TFlags , this > ,
306305 queryClient : QueryClient ,
307306 opts ?: BuilderOptions < TVars , TData , TError , TKey > ,
308307 ) : UseMutationOptions < TData , TError , TVars > {
@@ -319,7 +318,7 @@ export class QueryBuilderFrozen<
319318 }
320319
321320 getMutationFilters (
322- this : IsBoundThis < TFlags > ,
321+ this : IsBoundThis < TFlags , this > ,
323322 vars ?: TVars ,
324323 filters ?: MutationFilters < TData , TError , TVars > ,
325324 ) : MutationFilters < any , any , any > {
@@ -342,21 +341,21 @@ export class QueryBuilderFrozen<
342341 }
343342
344343 useMutation (
345- this : IsBoundThis < TFlags > ,
344+ this : IsBoundThis < TFlags , this > ,
346345 opts ?: BuilderOptions < TVars , TData , TError , TKey > ,
347346 ) : ReturnType < typeof useMutation < TData , TError , TVars > > {
348347 assertBound ( this ) ;
349348 const queryClient = useQueryClient ( this . config . queryClient ) ;
350349 return useMutation ( this . getMutationOptions ( queryClient , opts ) , this . config . queryClient ) ;
351350 }
352351
353- useIsMutating ( this : IsBoundThis < TFlags > , vars : TVars , filters ?: MutationFilters < TData , TError , TVars > ) : number {
352+ useIsMutating ( this : IsBoundThis < TFlags , this > , vars : TVars , filters ?: MutationFilters < TData , TError , TVars > ) : number {
354353 assertBound ( this ) ;
355354 return useIsMutating ( this . getMutationFilters ( vars , filters ) , this . config . queryClient ) ;
356355 }
357356
358357 useMutationState < TSelect = Mutation < TData , TError , TVars > > (
359- this : IsBoundThis < TFlags > ,
358+ this : IsBoundThis < TFlags , this > ,
360359 vars ?: TVars ,
361360 filters ?: MutationFilters < TData , TError , TVars > ,
362361 select ?: ( mt : Mutation < TData , TError , TVars > ) => TSelect ,
0 commit comments