diff --git a/packages/toolkit/src/query/react/buildHooks.ts b/packages/toolkit/src/query/react/buildHooks.ts index 2c99172a7b..68461cd9fe 100644 --- a/packages/toolkit/src/query/react/buildHooks.ts +++ b/packages/toolkit/src/query/react/buildHooks.ts @@ -202,6 +202,19 @@ export type UseQuerySubscriptionOptions = SubscriptionOptions & { refetchOnMountOrArgChange?: boolean | number } +/** + * Provides a way to reference the options accepted by the `useQuerySubscription` + * hook in userland code. + * + * Unlike other `Typed*` wrappers, this type has no generic parameters since + * {@linkcode UseQuerySubscriptionOptions} does not depend on a specific query + * definition. + * + * @since 2.2.8 + * @public + */ +export type TypedUseQuerySubscriptionOptions = UseQuerySubscriptionOptions + /** * A React hook that automatically triggers fetches of data from an endpoint, and 'subscribes' the component to the cached data. * @@ -1337,6 +1350,30 @@ export type UseMutationStateOptions< fixedCacheKey?: string } +/** + * Provides a way to define a "pre-typed" version of + * {@linkcode UseMutationStateOptions} with specific options for a given mutation. + * + * @template ResultType - The type of the result `data` returned by the mutation. + * @template QueryArg - The type of the argument passed into the mutation. + * @template BaseQuery - The type of the base query function being used. + * @template SelectedResult - The type of the selected result returned by the __`selectFromResult`__ function. + * + * @since 2.2.8 + * @public + */ +export type TypedUseMutationStateOptions< + ResultType, + QueryArg, + BaseQuery extends BaseQueryFn, + SelectedResult extends Record = MutationResultSelectorResult< + MutationDefinition + >, +> = UseMutationStateOptions< + MutationDefinition, + SelectedResult +> + export type UseMutationStateResult< D extends MutationDefinition, R, diff --git a/packages/toolkit/src/query/react/index.ts b/packages/toolkit/src/query/react/index.ts index c99f4d6452..2351bdc3f6 100644 --- a/packages/toolkit/src/query/react/index.ts +++ b/packages/toolkit/src/query/react/index.ts @@ -38,6 +38,8 @@ export type { TypedUseInfiniteQuerySubscription, TypedUseInfiniteQueryState, TypedLazyInfiniteQueryTrigger, + TypedUseQuerySubscriptionOptions, + TypedUseMutationStateOptions, } from './buildHooks' export { UNINITIALIZED_VALUE } from './constants' export { createApi, reactHooksModule, reactHooksModuleName }