TypeScript 将记录插入到多维数组(例如 - 数组<数字 | [数字,数字] | [字符串,数字] )>



我在其中一个组件文件中使用了"角度高图"。因此在angular component.ts文件中创建了一个类似于bellow的数组。它将存储数据并在html视图页面中绘制高图表(股票(。

public myData : Array< number | [number, number] | [string, number]>;

当我试图将数据推入时

this.myData.push(12540 ,2488);

它编译正确,但在运行时会变差。

core.js:1624 ERROR TypeError: Cannot read property 'push' of undefined
at third-page.component.ts:136
at Array.forEach (<anonymous>)
at SafeSubscriber._next (third-page.component.ts:118)
at 

知道吗?将数据插入这个mydata数组并绑定到图表的最佳方式是什么?

您需要实例化数组。尝试:

public myData : Array< number | [number, number] | [string, number]> = [];