diff --git a/packages/query-core/src/infiniteQueryObserver.ts b/packages/query-core/src/infiniteQueryObserver.ts index 59d6efa259..b1c18ac01c 100644 --- a/packages/query-core/src/infiniteQueryObserver.ts +++ b/packages/query-core/src/infiniteQueryObserver.ts @@ -4,6 +4,7 @@ import { hasPreviousPage, infiniteQueryBehavior, } from './infiniteQueryBehavior' +import type { Subscribable } from './subscribable' import type { DefaultError, DefaultedInfiniteQueryObserverOptions, @@ -16,7 +17,7 @@ import type { QueryKey, } from './types' import type { QueryClient } from './queryClient' -import type { NotifyOptions, ObserverFetchOptions } from './queryObserver' +import type { NotifyOptions } from './queryObserver' import type { Query } from './query' type InfiniteQueryObserverListener = ( @@ -38,17 +39,33 @@ export class InfiniteQueryObserver< TQueryKey > { // Type override - subscribe!: ( - listener?: InfiniteQueryObserverListener, - ) => () => void + subscribe!: Subscribable< + InfiniteQueryObserverListener + >['subscribe'] // Type override - getCurrentResult!: () => InfiniteQueryObserverResult + getCurrentResult!: ReplaceReturnType< + QueryObserver< + TQueryFnData, + TError, + TData, + InfiniteData, + TQueryKey + >['getCurrentResult'], + InfiniteQueryObserverResult + > // Type override - protected fetch!: ( - fetchOptions: ObserverFetchOptions, - ) => Promise> + protected fetch!: ReplaceReturnType< + QueryObserver< + TQueryFnData, + TError, + TData, + InfiniteData, + TQueryKey + >['fetch'], + Promise> + > constructor( client: QueryClient, @@ -176,3 +193,8 @@ export class InfiniteQueryObserver< return result as InfiniteQueryObserverResult } } + +type ReplaceReturnType< + TFunction extends (...args: Array) => unknown, + TReturn, +> = (...args: Parameters) => TReturn diff --git a/packages/query-core/src/queryObserver.ts b/packages/query-core/src/queryObserver.ts index 0a73184241..2971bc6d1a 100644 --- a/packages/query-core/src/queryObserver.ts +++ b/packages/query-core/src/queryObserver.ts @@ -34,7 +34,7 @@ export interface NotifyOptions { listeners?: boolean } -export interface ObserverFetchOptions extends FetchOptions { +interface ObserverFetchOptions extends FetchOptions { throwOnError?: boolean }