首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Redux Thunk调用另一个Thunk:缺少属性'type‘

Redux Thunk调用另一个Thunk:缺少属性'type‘
EN

Stack Overflow用户
提问于 2021-01-15 20:40:53
回答 1查看 90关注 0票数 0

我有一个接收id的thunk,并在商店的特定区域上执行一些逻辑。然后我想在商店的一个完全不同的区域上做一些逻辑。要做到这一点,我不能触发一个常规的操作,因为我将无法访问商店:我需要另一个thunk。

代码语言:javascript
复制
export const thunkOne = ({ id }) => async (dispatch: Dispatch, getState) => {
  const state = getState();

  await dispatch(thunkTwo({ id }));

  // ... do things with the state

  return;
};

现在thunkTwo是:

代码语言:javascript
复制
export const thunkOne = ({ id }) => (dispatch, getState) => {
  const { Bookmarks } = getState();
  // do some other logic

  return dispatch({
    type: ACTION_START,
    payload: {
      ...Bookmarks,
      id,
    },
  });
};

我得到了这个TypeScript错误:

代码语言:javascript
复制
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.

找不到问题。任何帮助都将受到欢迎!

EN

回答 1

Stack Overflow用户

发布于 2021-01-15 21:22:21

错误在调度的类型中,因为它应该是ThunkDispatch<any, void, Action>

代码语言:javascript
复制
export const thunkOne = ({ id }) => async (dispatch: ThunkDispatch<any, void, Action>, getState) => {
  const state = getState();

  await dispatch(thunkTwo({ id }));

  // ... do things with the state

  return;
};
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65736313

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档