Skip to content

Commit b5aa49c

Browse files
authored
Merge pull request #5218 from veeceey/fix/issue-5172-export-hook-options-types
Export hook options types for RTK Query hooks
2 parents cb04c8e + 20387a1 commit b5aa49c

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

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

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,19 @@ export type UseQuerySubscriptionOptions = SubscriptionOptions & {
202202
refetchOnMountOrArgChange?: boolean | number
203203
}
204204

205+
/**
206+
* Provides a way to reference the options accepted by the `useQuerySubscription`
207+
* hook in userland code.
208+
*
209+
* Unlike other `Typed*` wrappers, this type has no generic parameters since
210+
* {@linkcode UseQuerySubscriptionOptions} does not depend on a specific query
211+
* definition.
212+
*
213+
* @since 2.2.8
214+
* @public
215+
*/
216+
export type TypedUseQuerySubscriptionOptions = UseQuerySubscriptionOptions
217+
205218
/**
206219
* A React hook that automatically triggers fetches of data from an endpoint, and 'subscribes' the component to the cached data.
207220
*
@@ -1337,6 +1350,30 @@ export type UseMutationStateOptions<
13371350
fixedCacheKey?: string
13381351
}
13391352

1353+
/**
1354+
* Provides a way to define a "pre-typed" version of
1355+
* {@linkcode UseMutationStateOptions} with specific options for a given mutation.
1356+
*
1357+
* @template ResultType - The type of the result `data` returned by the mutation.
1358+
* @template QueryArg - The type of the argument passed into the mutation.
1359+
* @template BaseQuery - The type of the base query function being used.
1360+
* @template SelectedResult - The type of the selected result returned by the __`selectFromResult`__ function.
1361+
*
1362+
* @since 2.2.8
1363+
* @public
1364+
*/
1365+
export type TypedUseMutationStateOptions<
1366+
ResultType,
1367+
QueryArg,
1368+
BaseQuery extends BaseQueryFn,
1369+
SelectedResult extends Record<string, any> = MutationResultSelectorResult<
1370+
MutationDefinition<QueryArg, BaseQuery, string, ResultType, string>
1371+
>,
1372+
> = UseMutationStateOptions<
1373+
MutationDefinition<QueryArg, BaseQuery, string, ResultType, string>,
1374+
SelectedResult
1375+
>
1376+
13401377
export type UseMutationStateResult<
13411378
D extends MutationDefinition<any, any, any, any>,
13421379
R,

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ export type {
3838
TypedUseInfiniteQuerySubscription,
3939
TypedUseInfiniteQueryState,
4040
TypedLazyInfiniteQueryTrigger,
41+
TypedUseQuerySubscriptionOptions,
42+
TypedUseMutationStateOptions,
4143
} from './buildHooks'
4244
export { UNINITIALIZED_VALUE } from './constants'
4345
export { createApi, reactHooksModule, reactHooksModuleName }

0 commit comments

Comments
 (0)