【问题标题】:Typescript cryptic message when declaring function for one of my actions为我的一项操作声明功能时打字稿神秘消息
【发布时间】:2021-12-21 14:30:07
【问题描述】:

我正在使用 React、TypeScript 和 Redux。我似乎在为我的一项操作使用界面时遇到问题。我得到的神秘信息是:

Duplicate identifier 'number'.ts(2300)
Binding element 'number' implicitly has an 'any' type.ts(7031)

在 VS 代码中,limit: 和 skip: 上的数字都带有红色错误波浪线下划线。

截取我的代码:

interface TabNavUnitsProps {
  unitsToRegister: number,
  unit: { status: string, unitsRegisterCount: number },
  fetchRegisterAll: ({ limit: number, skip: number }) => Promise<void>
}

export class TabNavUnits extends React.Component<TabNavUnitsProps> {

  state = {
    unitsRegisterCount: 0
  }

  componentDidMount() {
    this.props.fetchRegisterAll({ limit: 1, skip: 1 })
    .then(() => {
      if(this.props.unit.status === fetchStates.success) {
        this.setState({ unitsRegisterCount: this.props.unit.unitsRegisterCount })
      }
    })
  }

我承认部分问题是我对此并不陌生,因此感谢任何愿意帮助或为我指明正确方向的人。

【问题讨论】:

    标签: reactjs typescript react-redux


    【解决方案1】:

    只要正确声明fetchRegisterAll

      fetchRegisterAll: (options: { limit:number , skip: number }) => Promise<void>
    

    【讨论】:

    • 可能是 options 或其他东西,而不是 a,但重点是。
    • @AKX 绝对有效点,已更新
    • @Drag13 非常感谢您的帮助。这立即奏效并解决了问题!
    • @xyz83242 StackOverflow 正是为了帮助而创建的 :) 可能你以后决定帮助别人 :)
    猜你喜欢
    • 2012-12-13
    • 2011-04-15
    • 2021-10-12
    • 1970-01-01
    • 2021-10-18
    • 2013-01-22
    • 2018-02-08
    • 2021-08-20
    • 1970-01-01
    相关资源
    最近更新 更多