Skip to content

Commit 94351bf

Browse files
committed
add more Typed wrappers and make sure they're all exported
1 parent 18ddd7e commit 94351bf

File tree

2 files changed

+157
-2
lines changed

2 files changed

+157
-2
lines changed

packages/toolkit/src/query/react/buildHooks.ts

+148-2
Original file line numberDiff line numberDiff line change
@@ -793,6 +793,22 @@ export type LazyInfiniteQueryTrigger<
793793
): InfiniteQueryActionCreatorResult<D>
794794
}
795795

796+
export type TypedLazyInfiniteQueryTrigger<
797+
ResultType,
798+
QueryArg,
799+
PageParam,
800+
BaseQuery extends BaseQueryFn,
801+
> = LazyInfiniteQueryTrigger<
802+
InfiniteQueryDefinition<
803+
QueryArg,
804+
PageParam,
805+
BaseQuery,
806+
string,
807+
ResultType,
808+
string
809+
>
810+
>
811+
796812
interface UseInfiniteQuerySubscriptionOptions<
797813
D extends InfiniteQueryDefinition<any, any, any, any, any>,
798814
> extends SubscriptionOptions {
@@ -890,6 +906,36 @@ export type InfiniteQueryStateSelector<
890906
D extends InfiniteQueryDefinition<any, any, any, any, any>,
891907
> = (state: UseInfiniteQueryStateDefaultResult<D>) => R
892908

909+
export type TypedInfiniteQueryStateSelector<
910+
ResultType,
911+
QueryArg,
912+
PageParam,
913+
BaseQuery extends BaseQueryFn,
914+
SelectedResult extends Record<
915+
string,
916+
any
917+
> = UseInfiniteQueryStateDefaultResult<
918+
InfiniteQueryDefinition<
919+
QueryArg,
920+
PageParam,
921+
BaseQuery,
922+
string,
923+
ResultType,
924+
string
925+
>
926+
>,
927+
> = InfiniteQueryStateSelector<
928+
SelectedResult,
929+
InfiniteQueryDefinition<
930+
QueryArg,
931+
PageParam,
932+
BaseQuery,
933+
string,
934+
ResultType,
935+
string
936+
>
937+
>
938+
893939
/**
894940
* 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.
895941
*
@@ -927,6 +973,22 @@ export type UseInfiniteQuery<
927973
'fetchNextPage' | 'fetchPreviousPage'
928974
>
929975

976+
export type TypedUseInfiniteQuery<
977+
ResultType,
978+
QueryArg,
979+
PageParam,
980+
BaseQuery extends BaseQueryFn,
981+
> = UseInfiniteQuery<
982+
InfiniteQueryDefinition<
983+
QueryArg,
984+
PageParam,
985+
BaseQuery,
986+
string,
987+
ResultType,
988+
string
989+
>
990+
>
991+
930992
/**
931993
* 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.
932994
*
@@ -987,6 +1049,33 @@ export type UseInfiniteQueryHookResult<
9871049
> = UseInfiniteQueryStateResult<D, R> &
9881050
Pick<UseInfiniteQuerySubscriptionResult<D>, 'refetch'>
9891051

1052+
export type TypedUseInfiniteQueryHookResult<
1053+
ResultType,
1054+
QueryArg,
1055+
PageParam,
1056+
BaseQuery extends BaseQueryFn,
1057+
R extends Record<string, any> = UseInfiniteQueryStateDefaultResult<
1058+
InfiniteQueryDefinition<
1059+
QueryArg,
1060+
PageParam,
1061+
BaseQuery,
1062+
string,
1063+
ResultType,
1064+
string
1065+
>
1066+
>,
1067+
> = UseInfiniteQueryHookResult<
1068+
InfiniteQueryDefinition<
1069+
QueryArg,
1070+
PageParam,
1071+
BaseQuery,
1072+
string,
1073+
ResultType,
1074+
string
1075+
>,
1076+
R
1077+
>
1078+
9901079
export type UseInfiniteQueryStateOptions<
9911080
D extends InfiniteQueryDefinition<any, any, any, any, any>,
9921081
R extends Record<string, any>,
@@ -1057,11 +1146,68 @@ export type UseInfiniteQueryStateOptions<
10571146
selectFromResult?: InfiniteQueryStateSelector<R, D>
10581147
}
10591148

1149+
export type TypedUseInfiniteQueryStateOptions<
1150+
ResultType,
1151+
QueryArg,
1152+
PageParam,
1153+
BaseQuery extends BaseQueryFn,
1154+
SelectedResult extends Record<
1155+
string,
1156+
any
1157+
> = UseInfiniteQueryStateDefaultResult<
1158+
InfiniteQueryDefinition<
1159+
QueryArg,
1160+
PageParam,
1161+
BaseQuery,
1162+
string,
1163+
ResultType,
1164+
string
1165+
>
1166+
>,
1167+
> = UseInfiniteQueryStateOptions<
1168+
InfiniteQueryDefinition<
1169+
QueryArg,
1170+
PageParam,
1171+
BaseQuery,
1172+
string,
1173+
ResultType,
1174+
string
1175+
>,
1176+
SelectedResult
1177+
>
1178+
10601179
export type UseInfiniteQueryStateResult<
1061-
_ extends InfiniteQueryDefinition<any, any, any, any, any>,
1062-
R,
1180+
D extends InfiniteQueryDefinition<any, any, any, any, any>,
1181+
R = UseInfiniteQueryStateDefaultResult<D>,
10631182
> = TSHelpersNoInfer<R>
10641183

1184+
export type TypedUseInfiniteQueryStateResult<
1185+
ResultType,
1186+
QueryArg,
1187+
PageParam,
1188+
BaseQuery extends BaseQueryFn,
1189+
R = UseInfiniteQueryStateDefaultResult<
1190+
InfiniteQueryDefinition<
1191+
QueryArg,
1192+
PageParam,
1193+
BaseQuery,
1194+
string,
1195+
ResultType,
1196+
string
1197+
>
1198+
>,
1199+
> = UseInfiniteQueryStateResult<
1200+
InfiniteQueryDefinition<
1201+
QueryArg,
1202+
PageParam,
1203+
BaseQuery,
1204+
string,
1205+
ResultType,
1206+
string
1207+
>,
1208+
R
1209+
>
1210+
10651211
type UseInfiniteQueryStateBaseResult<
10661212
D extends InfiniteQueryDefinition<any, any, any, any, any>,
10671213
> = InfiniteQuerySubState<D> & {

packages/toolkit/src/query/react/index.ts

+9
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,15 @@ export type {
2929
TypedUseLazyQuerySubscription,
3030
TypedUseQueryStateOptions,
3131
TypedUseLazyQueryStateResult,
32+
TypedUseInfiniteQuery,
33+
TypedUseInfiniteQueryHookResult,
34+
TypedUseInfiniteQueryStateResult,
35+
TypedUseInfiniteQuerySubscriptionResult,
36+
TypedUseInfiniteQueryStateOptions,
37+
TypedInfiniteQueryStateSelector,
38+
TypedUseInfiniteQuerySubscription,
39+
TypedUseInfiniteQueryState,
40+
TypedLazyInfiniteQueryTrigger,
3241
} from './buildHooks'
3342
export { UNINITIALIZED_VALUE } from './constants'
3443
export { createApi, reactHooksModule, reactHooksModuleName }

0 commit comments

Comments
 (0)