TypeScript子类型检查

时间:2016-05-08 12:40:06

标签: typescript

如果我有一个界面:

export interface IChartDatum {
    values: {
        x: number|Date,
        y: number
    }[],
    key: string;
    disabled: boolean;
    area?: boolean;
}

为什么在与private chartData:IChartDatum[] = [];

的集合进行交互时

以下内容无效:

this.chartData.push({
  values: [{x: "2", y: "5"}],
  key: status.name,
  disabled: status.name == 'archived'
});

但这是错误的有效:

this.chartData.find(item => item.key == status.name)
.values.push({x:"2", y: "5"});

enter image description here

1 个答案:

答案 0 :(得分:1)

这似乎是Webstorm缺乏TypeScript支持的问题。

两种给定的案例都在Visual Studio Code中生成相同的类型匹配错误。

相关问题