【发布时间】:2021-08-27 03:15:21
【问题描述】:
例子:
/* actions.ts */
export const getTeacherChats = createAsyncThunk(
'messenger/chats',
async (params, thunkAPI) => {
const response = await messenger.getTeacherChats()
if (response.ok) {
return response.data
}
return thunkAPI.rejectWithValue(response.error.text)
}
)
/* saga.ts */
function* teacherChatsWatcher() {
/* Error on the next line:
Argument of type 'AsyncThunkAction<TMessengerChatsResponse, void, {}>' is not assignable to parameter of type 'Action<any>'.
Property 'type' is missing in type 'AsyncThunkAction<TMessengerChatsResponse, void, {}>' but required in type 'Action<any>'. */
yield put(getTeacherChats())
}
export default function* messengerSaga() {
yield fork(teacherChatsWatcher)
}
是否可以通过 redux-saga 的 put effect 来调度 thunk action? 我应该怎么做才能从 saga 调度这个动作?
UPD: Action 以这种方式分派,并且工作正常,但仍然存在 TS 错误。
【问题讨论】:
标签: typescript redux redux-saga redux-thunk redux-toolkit