【问题标题】:Expected 0 arguments, but got 1.ts(2554) when implement redux use typesafe-actions for action预期 0 个参数,但在实现 redux 使用 typesafe-actions 时得到 1.ts(2554)
【发布时间】:2020-08-31 05:45:46
【问题描述】:

我正在使用打字稿。 我正在使用 typesafe-actions 进行 redux 操作

我的代码如下:

动作

export const setCount = createAction(
  types.SET_COUNT,
  resolve => (dataCount: CountModel) => resolve({ dataCount }),
);

预期 0 个参数,但得到 1.ts(2554)

我该如何解决?

index.tsx

  const setCount = (values: CountModel) => {
    dispatch(action.setCount(values))
  }

setCount 函数提示语法错误:

【问题讨论】:

  • 你解决了吗?

标签: reactjs typescript redux typesafe-actions


【解决方案1】:

在这里找到解决方案https://redux-toolkit.js.org/usage/usage-with-typescript

只需在方法后面加上类型即可:

export const setCount = createAction<number>(...);

【讨论】:

    猜你喜欢
    • 2022-08-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-18
    • 1970-01-01
    • 1970-01-01
    • 2020-11-07
    • 2019-12-28
    相关资源
    最近更新 更多