当我尝试在Angular中实现以下plunkr时,我收到以下错误消息.
Property 'series' does not exist on type 'Object'.
http://plnkr.co/edit/OQSFSKisIIWAH0megy4d?p=preview
我安装了“angular2-highcharts”:“^ 0.5.5”,
并输入“@ types / highcharts”:“^ 5.0.5”,
任何帮助,将不胜感激.
解决方法
当您将其键入为Object时,编译器不知道this.options中是否存在属性系列.
class AppComponent { options: any; }
或者您可以让编译器通过直接分配来从对象中推断出类型,以便正确输入this.options:
class AppComponent { options = { chart: { zoomType: 'xy' },series: ... // ... }; }
或者在界面中定义选项的类型:
interface Options { series: any[],// Should be typed to the shape of a series instead of `any` // and type other props like "chart","title" } class AppComponent { options: Options; constructor() { this.options = { chart: { zoomType: 'xy' },series: ... // ... }; } }