-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Open
Labels
Description
Hello! I'm using RTK with TypeScript.
I found this useful helper: TypedUseQueryHookResult with description:
/**
* Helper type to manually type the result
* of the `useQuery` hook in userland code.
*/
type TypedUseQueryHookResult<...> = ...
(source)
I can find many Typed* helpers, including TypedUseInfiniteQueryHookResult.
This last specific type has some issues:
- it doesn't have the jsdoc like the other helper types (maybe it's not ready?)
- it's missing
ofthe fieldsfetchNextPageandfetchPreviousPage
A workaround in userland for the second point (missing fields) is something like this:
import type {
BaseQueryFn,
TypedUseInfiniteQueryHookResult,
TypedUseInfiniteQuerySubscriptionResult,
} from '@reduxjs/toolkit/query/react';
export type MyComponentProps = {
query: TypedUseInfiniteQueryHookResult<MyResultType, unknown, unknown, BaseQueryFn> &
Pick<
TypedUseInfiniteQuerySubscriptionResult<
MyResultType,
unknown,
unknown,
BaseQueryFn
>,
'fetchNextPage' | 'fetchPreviousPage'
>;
};Which is similar to the pattern on lines 1002-1005
Would be great to have this enhancement available in the library. What do you think?