首页 文章

流和Javascript . 无法调用函数,因为对象类型中缺少属性

提问于
浏览
0

使用流类型检查器键入提示我的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给了我一个错误

Cannot call units.findIndex because property findIndex is missing in object type [1].

1 回答

  • 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
      });
    
      ....
      ....
    }
    

    解决这个问题

相关问题