-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
fix(react-query): types for useSuspenseQuery #5755
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
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 |
---|---|---|
|
@@ -12,6 +12,7 @@ import type { | |
QueryKey, | ||
QueryObserverOptions, | ||
QueryObserverResult, | ||
QueryObserverSuccessResult, | ||
WithRequired, | ||
} from '@tanstack/query-core' | ||
|
||
|
@@ -36,6 +37,16 @@ export interface UseQueryOptions< | |
'queryKey' | ||
> {} | ||
|
||
export interface UseSuspenseQueryOptions< | ||
TQueryFnData = unknown, | ||
TError = DefaultError, | ||
TData = TQueryFnData, | ||
TQueryKey extends QueryKey = QueryKey, | ||
> extends Omit< | ||
UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>, | ||
'enabled' | 'suspense' | 'throwOnError' | 'placeholderData' | ||
> {} | ||
|
||
export interface UseInfiniteQueryOptions< | ||
TQueryFnData = unknown, | ||
TError = DefaultError, | ||
|
@@ -65,6 +76,11 @@ export type UseQueryResult< | |
TError = DefaultError, | ||
> = UseBaseQueryResult<TData, TError> | ||
|
||
export type UseSuspenseQueryResult< | ||
TData = unknown, | ||
TError = DefaultError, | ||
> = Omit<QueryObserverSuccessResult<TData, TError>, 'isPlaceholderData'> | ||
Comment on lines
+79
to
+82
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 DefinedQueryObserverResult<TData = unknown, TError = DefaultError> = QueryObserverRefetchErrorResult<TData, TError> | QueryObserverSuccessResult<TData, TError>; We just need only interface QueryObserverRefetchErrorResult<TData = unknown, TError = DefaultError> extends QueryObserverBaseResult<TData, TError> {
data: TData;
error: TError;
isError: true;
isPending: false;
isLoadingError: false;
isRefetchError: true;
isSuccess: false;
status: 'error';
}
interface QueryObserverSuccessResult<TData = unknown, TError = DefaultError> extends QueryObserverBaseResult<TData, TError> {
data: TData;
error: null;
isError: false;
isPending: false;
isLoadingError: false;
isRefetchError: false;
isSuccess: true;
status: 'success';
} |
||
|
||
export type DefinedUseQueryResult< | ||
TData = unknown, | ||
TError = DefaultError, | ||
|
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 thought It would be better that useSuspenseQuery have its
QueryOptions
type andResult
type likeUseQueryOptions
,UseQueryResult
for useQueryIf useSuspenseQuery should be provided as an API of the same hierarchy as useQuery, I thought it would be better to provide the types(
UseSuspenseQueryOptions
,UseSuspenseQueryResult
) in the same hierarchy.