流和Javascript。由于对象类型缺少属性,因此无法调用函数

时间:2018-08-06 00:04:44

标签: javascript reactjs flowtype

使用流类型检查器键入提示我的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
  });

  ....
  ....
}

流程给我一个错误

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

1 个答案:

答案 0 :(得分:0)

感谢@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
  });

  ....
  ....
}

解决此问题

相关问题