【问题标题】:Flow and Javascript . Cannot call function because property is missing in object type流和 Javascript 。无法调用函数,因为对象类型中缺少属性
【发布时间】:2018-08-06 00:04:43
【问题描述】:

使用流类型检查器输入提示我的 javascript 代码

const functionName = (name: string, newvalue:string , units: {}) :{} =>  {

  //Obj to be returned
  const returnObj = {};


  //index of a event.target.
  const indexofChange: number = units.findIndex(matchElement, {
    name: name
  });

  ....
  ....
}

Flow 给我一个错误

无法调用 units.findIndex,因为对象类型 [1] 中缺少属性 findIndex。

【问题讨论】:

  • findIndex 是一个数组方法。它不存在于常规对象上。

标签: javascript reactjs flowtype


【解决方案1】:

谢谢@Tholle

const functionName = (name: string, newvalue:string , units: Array<Object>) :Array<Object> =>  {

  //Array to be returned
  const returnArray:Array<Object> = [];


  //index of a event.target.
  const indexofChange: number = units.findIndex(matchElement, {
    name: name
  });

  ....
  ....
}

解决这个问题

【讨论】:

    猜你喜欢
    • 2018-10-24
    • 2023-03-14
    • 2019-06-18
    • 2021-10-26
    • 2019-07-15
    • 1970-01-01
    • 1970-01-01
    • 2019-07-05
    • 1970-01-01
    相关资源
    最近更新 更多