From bdc3766e7efabd870f2924405fc40f3c07a1aa70 Mon Sep 17 00:00:00 2001 From: Jonghyeon Ko Date: Sat, 22 Jul 2023 03:47:21 +0900 Subject: [PATCH] fix: types for useSuspenseInfiniteQuery --- packages/react-query/src/types.ts | 25 +++++++++++++++ .../src/useSuspenseInfiniteQuery.ts | 32 ++++++++++--------- 2 files changed, 42 insertions(+), 15 deletions(-) diff --git a/packages/react-query/src/types.ts b/packages/react-query/src/types.ts index a2a2187046..532e3a9057 100644 --- a/packages/react-query/src/types.ts +++ b/packages/react-query/src/types.ts @@ -6,6 +6,7 @@ import type { DefinedQueryObserverResult, InfiniteQueryObserverOptions, InfiniteQueryObserverResult, + InfiniteQueryObserverSuccessResult, MutateFunction, MutationObserverOptions, MutationObserverResult, @@ -66,6 +67,25 @@ export interface UseInfiniteQueryOptions< 'queryKey' > {} +export interface UseSuspenseInfiniteQueryOptions< + TQueryFnData = unknown, + TError = DefaultError, + TData = TQueryFnData, + TQueryData = TQueryFnData, + TQueryKey extends QueryKey = QueryKey, + TPageParam = unknown, +> extends Omit< + UseInfiniteQueryOptions< + TQueryFnData, + TError, + TData, + TQueryData, + TQueryKey, + TPageParam + >, + 'enabled' | 'suspense' | 'throwOnError' | 'placeholderData' + > {} + export type UseBaseQueryResult< TData = unknown, TError = DefaultError, @@ -96,6 +116,11 @@ export type DefinedUseInfiniteQueryResult< TError = DefaultError, > = DefinedInfiniteQueryObserverResult +export type UseSuspenseInfiniteQueryResult< + TData = unknown, + TError = DefaultError, +> = Omit, 'isPlaceholderData'> + export interface UseMutationOptions< TData = unknown, TError = DefaultError, diff --git a/packages/react-query/src/useSuspenseInfiniteQuery.ts b/packages/react-query/src/useSuspenseInfiniteQuery.ts index 4ea30dc1cb..61450eb463 100644 --- a/packages/react-query/src/useSuspenseInfiniteQuery.ts +++ b/packages/react-query/src/useSuspenseInfiniteQuery.ts @@ -1,15 +1,20 @@ 'use client' import { InfiniteQueryObserver } from '@tanstack/query-core' import { useBaseQuery } from './useBaseQuery' -import type { QueryObserver } from '@tanstack/query-core' +import type { + InfiniteQueryObserverSuccessResult, + QueryObserver, +} from '@tanstack/query-core' import type { DefaultError, InfiniteData, QueryClient, QueryKey, } from '@tanstack/query-core' -import type { DefinedUseInfiniteQueryResult } from './types' -import type { UseInfiniteQueryOptions } from './types' +import type { + UseSuspenseInfiniteQueryOptions, + UseSuspenseInfiniteQueryResult, +} from './types' export function useSuspenseInfiniteQuery< TQueryFnData, @@ -18,19 +23,16 @@ export function useSuspenseInfiniteQuery< TQueryKey extends QueryKey = QueryKey, TPageParam = unknown, >( - options: Omit< - UseInfiniteQueryOptions< - TQueryFnData, - TError, - TData, - TQueryFnData, - TQueryKey, - TPageParam - >, - 'enabled' | 'suspense' | 'throwOnError' | 'placeholderData' + options: UseSuspenseInfiniteQueryOptions< + TQueryFnData, + TError, + TData, + TQueryFnData, + TQueryKey, + TPageParam >, queryClient?: QueryClient, -): Omit, 'isPlaceholderData'> { +): UseSuspenseInfiniteQueryResult { return useBaseQuery( { ...options, @@ -41,5 +43,5 @@ export function useSuspenseInfiniteQuery< // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion InfiniteQueryObserver as typeof QueryObserver, queryClient, - ) as DefinedUseInfiniteQueryResult + ) as InfiniteQueryObserverSuccessResult }