From 44dc340bc6daa2e313d7f9e1072db71bafd8f975 Mon Sep 17 00:00:00 2001 From: Jonghyeon Ko Date: Sun, 18 Aug 2024 22:37:12 +0900 Subject: [PATCH 1/2] fix(query-core): type override subscribe in InfiniteQueryObserver more clearly --- packages/query-core/src/infiniteQueryObserver.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/query-core/src/infiniteQueryObserver.ts b/packages/query-core/src/infiniteQueryObserver.ts index 59d6efa259..084a18e827 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, @@ -38,9 +39,9 @@ export class InfiniteQueryObserver< TQueryKey > { // Type override - subscribe!: ( - listener?: InfiniteQueryObserverListener, - ) => () => void + subscribe!: Subscribable< + InfiniteQueryObserverListener + >['subscribe'] // Type override getCurrentResult!: () => InfiniteQueryObserverResult From ccb4a62a84e23bb8cc56ce6275033911de5978cc Mon Sep 17 00:00:00 2001 From: Jonghyeon Ko Date: Tue, 20 Aug 2024 00:03:41 +0900 Subject: [PATCH 2/2] chore: update --- .../query-core/src/infiniteQueryObserver.ts | 31 ++++++++++++++++--- packages/query-core/src/queryObserver.ts | 2 +- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/packages/query-core/src/infiniteQueryObserver.ts b/packages/query-core/src/infiniteQueryObserver.ts index 084a18e827..b1c18ac01c 100644 --- a/packages/query-core/src/infiniteQueryObserver.ts +++ b/packages/query-core/src/infiniteQueryObserver.ts @@ -17,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 = ( @@ -44,12 +44,28 @@ export class InfiniteQueryObserver< >['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, @@ -177,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 }