Skip to content

Commit 93bb369

Browse files
committed
Add TypedUseQueryStateOptions helper type
1 parent e4791ea commit 93bb369

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,30 @@ export type UseQueryStateOptions<
430430
selectFromResult?: QueryStateSelector<R, D>
431431
}
432432

433+
/**
434+
* Allows you to define a "pre-typed" version of
435+
* {@linkcode UseQueryStateOptions} for a specific query.
436+
*
437+
* @template ResultType - The type of the data returned by the query.
438+
* @template QueryArg - The type of the argument passed to the query.
439+
* @template BaseQuery - The type of the base query function used by the query.
440+
* @template SelectedResult - The type of the selected result returned by __`selectFromResult`__.
441+
*
442+
* @since 2.7.8
443+
* @public
444+
*/
445+
export type TypedUseQueryStateOptions<
446+
ResultType,
447+
QueryArg,
448+
BaseQuery extends BaseQueryFn,
449+
SelectedResult extends Record<string, any> = UseQueryStateDefaultResult<
450+
QueryDefinition<QueryArg, BaseQuery, string, ResultType, string>
451+
>,
452+
> = UseQueryStateOptions<
453+
QueryDefinition<QueryArg, BaseQuery, string, ResultType, string>,
454+
SelectedResult
455+
>
456+
433457
export type UseQueryStateResult<
434458
_ extends QueryDefinition<any, any, any, any>,
435459
R,

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export type {
2626
TypedUseQuery,
2727
TypedUseQuerySubscription,
2828
TypedUseLazyQuerySubscription,
29+
TypedUseQueryStateOptions,
2930
} from './buildHooks'
3031
export { UNINITIALIZED_VALUE } from './constants'
3132
export { createApi, reactHooksModule, reactHooksModuleName }

0 commit comments

Comments
 (0)