我有一个接收id的thunk,并在商店的特定区域上执行一些逻辑。然后我想在商店的一个完全不同的区域上做一些逻辑。要做到这一点,我不能触发一个常规的操作,因为我将无法访问商店:我需要另一个thunk。
export const thunkOne = ({ id }) => async (dispatch: Dispatch, getState) => {
const state = getState();
await dispatch(thunkTwo({ id }));
// ... do things with the state
return;
};现在thunkTwo是:
export const thunkOne = ({ id }) => (dispatch, getState) => {
const { Bookmarks } = getState();
// do some other logic
return dispatch({
type: ACTION_START,
payload: {
...Bookmarks,
id,
},
});
};我得到了这个TypeScript错误:
Argument of type '(dispatch: any, getState: any) => any' is not assignable to
parameter of type 'AnyAction'.
Property 'type' is missing in type '(dispatch: any, getState: any) => any' but
required in type 'AnyAction'.ts(2345)
index.d.ts(21, 3): 'type' is declared here.找不到问题。任何帮助都将受到欢迎!
发布于 2021-01-15 21:22:21
错误在调度的类型中,因为它应该是ThunkDispatch<any, void, Action>
export const thunkOne = ({ id }) => async (dispatch: ThunkDispatch<any, void, Action>, getState) => {
const state = getState();
await dispatch(thunkTwo({ id }));
// ... do things with the state
return;
};https://stackoverflow.com/questions/65736313
复制相似问题