Ali Habibzadeh
Ali Habibzadeh

Reputation: 11558

TypeScript subtype checking

If I have an interface:

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

why while interacting with a collection of: private chartData:IChartDatum[] = [];

The following is correctly invalid:

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

But this is wrongly valid:

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

enter image description here

Upvotes: 0

Views: 475

Answers (1)

toskv
toskv

Reputation: 31600

This seems to be an issue with Webstorm's lacking TypeScript support.

Both given cases generate the same type matching error in Visual Studio Code.

Upvotes: 1

Related Questions