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