Skip to content

Commit d57a84c

Browse files
committed
Add TypedOnQueryStarted type
1 parent 24286f1 commit d57a84c

File tree

7 files changed

+489
-6
lines changed

7 files changed

+489
-6
lines changed

packages/toolkit/src/query/core/buildMiddleware/index.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export type {
3535
MutationLifecycleApi,
3636
QueryLifecycleApi,
3737
ReferenceQueryLifecycle,
38+
TypedOnQueryStarted,
3839
} from './queryLifecycle'
3940
export type { SubscriptionSelectors } from './types'
4041

@@ -148,7 +149,12 @@ export function buildMiddleware<
148149
{ status: QueryStatus.uninitialized }
149150
>,
150151
) {
151-
return (input.api.endpoints[querySubState.endpointName] as ApiEndpointQuery<any, any>).initiate(querySubState.originalArgs as any, {
152+
return (
153+
input.api.endpoints[querySubState.endpointName] as ApiEndpointQuery<
154+
any,
155+
any
156+
>
157+
).initiate(querySubState.originalArgs as any, {
152158
subscribe: false,
153159
forceRefetch: true,
154160
})

packages/toolkit/src/query/core/buildMiddleware/queryLifecycle.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,45 @@ export type QueryLifecycleQueryExtraOptions<
116116
): Promise<void> | void
117117
}
118118

119+
/**
120+
* @since 2.4.0
121+
* @public
122+
*/
123+
export type TypedOnQueryStarted<
124+
ResultType,
125+
QueryArg,
126+
BaseQuery extends BaseQueryFn,
127+
ReducerPath extends string = string,
128+
DefinitionType extends 'query' | 'mutation' = 'query' | 'mutation',
129+
> = 'query' | 'mutation' extends DefinitionType
130+
? QueryLifecycleMutationExtraOptions<
131+
ResultType,
132+
QueryArg,
133+
BaseQuery,
134+
ReducerPath
135+
>['onQueryStarted'] &
136+
QueryLifecycleQueryExtraOptions<
137+
ResultType,
138+
QueryArg,
139+
BaseQuery,
140+
ReducerPath
141+
>['onQueryStarted']
142+
: 'query' extends DefinitionType
143+
? QueryLifecycleQueryExtraOptions<
144+
ResultType,
145+
QueryArg,
146+
BaseQuery,
147+
ReducerPath
148+
>['onQueryStarted']
149+
: 'mutation' extends DefinitionType
150+
? QueryLifecycleMutationExtraOptions<
151+
ResultType,
152+
QueryArg,
153+
BaseQuery,
154+
ReducerPath
155+
>['onQueryStarted']
156+
: never
157+
119158
export type QueryLifecycleMutationExtraOptions<
120159
ResultType,
121160
QueryArg,

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ export type {
2424
QueryCacheLifecycleApi,
2525
QueryLifecycleApi,
2626
SubscriptionSelectors,
27-
} from './buildMiddleware'
27+
TypedOnQueryStarted,
28+
} from './buildMiddleware/index'
2829
export { skipToken } from './buildSelectors'
2930
export type {
3031
MutationResultSelectorResult,

packages/toolkit/src/query/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ export type { CreateApi, CreateApiOptions } from './createApi'
6868
export { buildCreateApi } from './createApi'
6969
export { _NEVER, fakeBaseQuery } from './fakeBaseQuery'
7070
export { copyWithStructuralSharing } from './utils/copyWithStructuralSharing'
71-
export { createApi, coreModule, coreModuleName } from './core'
71+
export { createApi, coreModule, coreModuleName } from './core/index'
72+
export type { TypedOnQueryStarted } from './core/index'
7273
export type {
7374
ApiEndpointMutation,
7475
ApiEndpointQuery,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ export type QueryStateSelector<
421421
* @template BaseQueryFunctionType - The type of the base query function being used.
422422
* @template SelectedResultType - The type of the selected result returned by the __`selectFromResult`__ function.
423423
*
424-
* @since 2.7.9
424+
* @since 2.3.0
425425
* @public
426426
*/
427427
export type TypedQueryStateSelector<
@@ -604,7 +604,7 @@ export type UseQueryStateOptions<
604604
* @template BaseQuery - The type of the base query function being used.
605605
* @template SelectedResult - The type of the selected result returned by the __`selectFromResult`__ function.
606606
*
607-
* @since 2.7.8
607+
* @since 2.2.8
608608
* @public
609609
*/
610610
export type TypedUseQueryStateOptions<

0 commit comments

Comments
 (0)