繁体   English   中英

流类型推断不起作用

[英]Flow type inference not working

我有以下代码:

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();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM