[Vuejs]-Property 'y' does not exist on type 'number'

2👍

buyRatioChartdata.values is set to buyRatioRows, created from getRowsPerDateBuyRatio(), which returns an array:

// `rows` is an array of `{ x: number[], y: number[] }`
// `y` is the maximum "buy ratio" in an items list
return [rows, y]

For the first problem you encountered:

max: Math.max(...buyRatioChartdata.values.y) + 20,

buyRatioChartdata.values is an array, which does not have a y property. I think you’re trying to get the maximum y-value from the array in buyRatioChartdata.values[0], but that calculation is already stored in buyRatioChartdata.values[1], so you could just use that:

max: (buyRatioChartdata.values[1] as number) + 20,

The second problem is in:

this.seriesRevBuy[1].data = buyRatioChartdata.values[0].y.map((item: number) => item.toFixed(1));

TypeScript can’t infer which type to use for buyRatioChartdata.values (as indicated in the error message). You could resolve it with a type assertion to the intended object:

const rows = buyRatioChartdata.values[0] as { x: number[], y: number[] };
this.seriesRevBuy[1].data = rows.y.map((item: number) => item.toFixed(1));

Leave a comment