Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/370.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 流类型推断不起作用_Javascript_Flowtype - Fatal编程技术网

Javascript 流类型推断不起作用

Javascript 流类型推断不起作用,javascript,flowtype,Javascript,Flowtype,我有以下代码: export const notesService = { getChannelOptions(): ChannelOption[] { return [...channelOptions]; }, getChannelLabelFromValue(value: string): string { let x =this.getChannelOptions(); x = x + 3; const label

我有以下代码:

export const notesService = {

   getChannelOptions(): ChannelOption[] {
      return [...channelOptions];
   },

   getChannelLabelFromValue(value: string): string {
      let x =this.getChannelOptions();
      x = x  + 3;
      const label = channelOptions.filter(co => co.value === value);
     return label[0] ? label[0].label : "";
   }

}
问题是当我尝试向数组中添加3时,流会抛出错误,我必须做什么


顺便说一句:如果我在noteService之外声明getChannelOptions作为一个函数,它就可以工作。

我通过显式声明解决了这个问题,但可能有更好的方法

let x = notesService.getChannelOptions();