And*_*ald 8 typescript angular2-highcharts
当我尝试在Angular中实现以下plunkr时,我收到以下错误消息.
Property 'series' does not exist on type 'Object'.
Run Code Online (Sandbox Code Playgroud)
http://plnkr.co/edit/OQSFSKisIIWAH0megy4d?p=preview
我安装了"angular2-highcharts":"^ 0.5.5",输入"@ types/highcharts":"^ 5.0.5",
任何帮助,将不胜感激.
当您将其键入为 时,编译器不知道该属性series是否存在。this.optionsObject
为了克服这个问题,您可以删除属性的输入(懒惰的方法):
class AppComponent {
options: any;
}
Run Code Online (Sandbox Code Playgroud)
或者您可以让编译器通过直接分配对象来推断对象的类型,以便this.options正确键入:
class AppComponent {
options = {
chart: {
zoomType: 'xy'
},
series: ...
// ...
};
}
Run Code Online (Sandbox Code Playgroud)
或者options在接口中定义类型:
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: ...
// ...
};
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4379 次 |
| 最近记录: |