小编Adi*_*tov的帖子

类型“(dispatch: Dispatch) => void”的参数不可分配给“AnyAction”类型的参数

错误本身:

(alias) deleteCategory(id: number): (dispatch: Dispatch<AnyAction>) => void
import deleteCategory
Argument of type '(dispatch: Dispatch) => void' is not assignable to parameter of type 'AnyAction'.
  Property 'type' is missing in type '(dispatch: Dispatch) => void' but required in type 'AnyAction'.ts(2345)
Run Code Online (Sandbox Code Playgroud)

有问题的代码:

export function getCategoryList(
  categories: CategoryType[],
  dispatch: Dispatch
) {
  return categories.map((category: CategoryType) => ({
    ...category,
    onDelete: () => {
      dispatch(deleteCategory(category._id)); //FIXME: Fix this. Error Appears here
    },
  }));
}
Run Code Online (Sandbox Code Playgroud)

删除类别的实现:

export const deleteCategory = (id: number) => (dispatch: Dispatch) …
Run Code Online (Sandbox Code Playgroud)

async-await reactjs redux redux-thunk react-redux

11
推荐指数
1
解决办法
2万
查看次数

标签 统计

async-await ×1

react-redux ×1

reactjs ×1

redux ×1

redux-thunk ×1