Skip to content

Commit 7f1ef6b

Browse files
committed
require dispatch type to extend thunkdispatch
1 parent 7251a67 commit 7f1ef6b

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

packages/toolkit/src/createAsyncThunk.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ export const miniSerializeError = (value: any): SerializedError => {
116116

117117
export type AsyncThunkConfig = {
118118
state?: unknown
119-
dispatch?: Dispatch
119+
dispatch?: ThunkDispatch<unknown, unknown, UnknownAction>
120120
extra?: unknown
121121
rejectValue?: unknown
122122
serializedErrorType?: unknown
@@ -577,7 +577,7 @@ export const createAsyncThunk = /* @__PURE__ */ (() => {
577577

578578
function actionCreator(
579579
arg: ThunkArg,
580-
): AsyncThunkAction<Returned, ThunkArg, ThunkApiConfig> {
580+
): AsyncThunkAction<Returned, ThunkArg, Required<ThunkApiConfig>> {
581581
return (dispatch, getState, extra) => {
582582
const requestId = options?.idGenerator
583583
? options.idGenerator(arg)
@@ -617,7 +617,7 @@ export const createAsyncThunk = /* @__PURE__ */ (() => {
617617
}
618618
abortController.signal.addEventListener('abort', abortHandler)
619619
})
620-
;(dispatch as ThunkDispatch<unknown, unknown, UnknownAction>)(
620+
dispatch(
621621
pending(
622622
requestId,
623623
arg,
@@ -679,9 +679,7 @@ export const createAsyncThunk = /* @__PURE__ */ (() => {
679679
(finalAction as any).meta.condition
680680

681681
if (!skipDispatch) {
682-
;(dispatch as ThunkDispatch<unknown, unknown, UnknownAction>)(
683-
finalAction as any,
684-
)
682+
dispatch(finalAction as any)
685683
}
686684
return finalAction
687685
})()

0 commit comments

Comments
 (0)