diff --git a/packages/toolkit/src/query/react/buildHooks.ts b/packages/toolkit/src/query/react/buildHooks.ts index 1f08eab47b..3af7436da2 100644 --- a/packages/toolkit/src/query/react/buildHooks.ts +++ b/packages/toolkit/src/query/react/buildHooks.ts @@ -793,6 +793,22 @@ export type LazyInfiniteQueryTrigger< ): InfiniteQueryActionCreatorResult } +export type TypedLazyInfiniteQueryTrigger< + ResultType, + QueryArg, + PageParam, + BaseQuery extends BaseQueryFn, +> = LazyInfiniteQueryTrigger< + InfiniteQueryDefinition< + QueryArg, + PageParam, + BaseQuery, + string, + ResultType, + string + > +> + interface UseInfiniteQuerySubscriptionOptions< D extends InfiniteQueryDefinition, > extends SubscriptionOptions { @@ -890,6 +906,36 @@ export type InfiniteQueryStateSelector< D extends InfiniteQueryDefinition, > = (state: UseInfiniteQueryStateDefaultResult) => R +export type TypedInfiniteQueryStateSelector< + ResultType, + QueryArg, + PageParam, + BaseQuery extends BaseQueryFn, + SelectedResult extends Record< + string, + any + > = UseInfiniteQueryStateDefaultResult< + InfiniteQueryDefinition< + QueryArg, + PageParam, + BaseQuery, + string, + ResultType, + string + > + >, +> = InfiniteQueryStateSelector< + SelectedResult, + InfiniteQueryDefinition< + QueryArg, + PageParam, + BaseQuery, + string, + ResultType, + string + > +> + /** * A React hook that automatically triggers fetches of data from an endpoint, 'subscribes' the component to the cached data, and reads the request status and cached data from the Redux store. The component will re-render as the loading status changes and the data becomes available. Additionally, it will cache multiple "pages" worth of responses within a single cache entry, and allows fetching more pages forwards and backwards from the current cached pages. * @@ -927,6 +973,22 @@ export type UseInfiniteQuery< 'fetchNextPage' | 'fetchPreviousPage' > +export type TypedUseInfiniteQuery< + ResultType, + QueryArg, + PageParam, + BaseQuery extends BaseQueryFn, +> = UseInfiniteQuery< + InfiniteQueryDefinition< + QueryArg, + PageParam, + BaseQuery, + string, + ResultType, + string + > +> + /** * A React hook that reads the request status and cached data from the Redux store. The component will re-render as the loading status changes and the data becomes available. * @@ -987,6 +1049,33 @@ export type UseInfiniteQueryHookResult< > = UseInfiniteQueryStateResult & Pick, 'refetch'> +export type TypedUseInfiniteQueryHookResult< + ResultType, + QueryArg, + PageParam, + BaseQuery extends BaseQueryFn, + R extends Record = UseInfiniteQueryStateDefaultResult< + InfiniteQueryDefinition< + QueryArg, + PageParam, + BaseQuery, + string, + ResultType, + string + > + >, +> = UseInfiniteQueryHookResult< + InfiniteQueryDefinition< + QueryArg, + PageParam, + BaseQuery, + string, + ResultType, + string + >, + R +> + export type UseInfiniteQueryStateOptions< D extends InfiniteQueryDefinition, R extends Record, @@ -1057,11 +1146,68 @@ export type UseInfiniteQueryStateOptions< selectFromResult?: InfiniteQueryStateSelector } +export type TypedUseInfiniteQueryStateOptions< + ResultType, + QueryArg, + PageParam, + BaseQuery extends BaseQueryFn, + SelectedResult extends Record< + string, + any + > = UseInfiniteQueryStateDefaultResult< + InfiniteQueryDefinition< + QueryArg, + PageParam, + BaseQuery, + string, + ResultType, + string + > + >, +> = UseInfiniteQueryStateOptions< + InfiniteQueryDefinition< + QueryArg, + PageParam, + BaseQuery, + string, + ResultType, + string + >, + SelectedResult +> + export type UseInfiniteQueryStateResult< - _ extends InfiniteQueryDefinition, - R, + D extends InfiniteQueryDefinition, + R = UseInfiniteQueryStateDefaultResult, > = TSHelpersNoInfer +export type TypedUseInfiniteQueryStateResult< + ResultType, + QueryArg, + PageParam, + BaseQuery extends BaseQueryFn, + R = UseInfiniteQueryStateDefaultResult< + InfiniteQueryDefinition< + QueryArg, + PageParam, + BaseQuery, + string, + ResultType, + string + > + >, +> = UseInfiniteQueryStateResult< + InfiniteQueryDefinition< + QueryArg, + PageParam, + BaseQuery, + string, + ResultType, + string + >, + R +> + type UseInfiniteQueryStateBaseResult< D extends InfiniteQueryDefinition, > = InfiniteQuerySubState & { diff --git a/packages/toolkit/src/query/react/index.ts b/packages/toolkit/src/query/react/index.ts index e9fda233ae..7b96482c26 100644 --- a/packages/toolkit/src/query/react/index.ts +++ b/packages/toolkit/src/query/react/index.ts @@ -29,6 +29,15 @@ export type { TypedUseLazyQuerySubscription, TypedUseQueryStateOptions, TypedUseLazyQueryStateResult, + TypedUseInfiniteQuery, + TypedUseInfiniteQueryHookResult, + TypedUseInfiniteQueryStateResult, + TypedUseInfiniteQuerySubscriptionResult, + TypedUseInfiniteQueryStateOptions, + TypedInfiniteQueryStateSelector, + TypedUseInfiniteQuerySubscription, + TypedUseInfiniteQueryState, + TypedLazyInfiniteQueryTrigger, } from './buildHooks' export { UNINITIALIZED_VALUE } from './constants' export { createApi, reactHooksModule, reactHooksModuleName }