-
-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(react-query): types for useSuspenseInfiniteQuery #5766
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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<TData, TError> | ||
|
||
export type UseSuspenseInfiniteQueryResult< | ||
TData = unknown, | ||
TError = DefaultError, | ||
> = Omit<InfiniteQueryObserverSuccessResult<TData, TError>, 'isPlaceholderData'> | ||
Comment on lines
+119
to
+122
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought If we don't have type DefinedInfiniteQueryObserverResult<TData = unknown, TError = DefaultError> = InfiniteQueryObserverRefetchErrorResult<TData, TError> | InfiniteQueryObserverSuccessResult<TData, TError>; We just need only InfiniteQueryObserverSuccessResult for useSuspenseInfiniteQuery. interface InfiniteQueryObserverRefetchErrorResult<TData = unknown, TError = DefaultError> extends InfiniteQueryObserverBaseResult<TData, TError> {
data: TData;
error: TError;
isError: true;
isPending: false;
isLoadingError: false;
isRefetchError: true;
isSuccess: false;
status: 'error';
}
interface InfiniteQueryObserverSuccessResult<TData = unknown, TError = DefaultError> extends InfiniteQueryObserverBaseResult<TData, TError> {
data: TData;
error: null;
isError: false;
isPending: false;
isLoadingError: false;
isRefetchError: false;
isSuccess: true;
status: 'success';
} This change is needed by same reason with #5755 (comment) |
||
|
||
export interface UseMutationOptions< | ||
TData = unknown, | ||
TError = DefaultError, | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -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<DefinedUseInfiniteQueryResult<TData, TError>, 'isPlaceholderData'> { | ||||||
): UseSuspenseInfiniteQueryResult<TData, TError> { | ||||||
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<TData, TError> | ||||||
) as InfiniteQueryObserverSuccessResult<TData, TError> | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think alternative solution is below suggestion
Suggested change
|
||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added UseSuspenseInfiniteQueryOptions, cause of same reason with why we need UseSuspenseQueryOptions