Typescript和Angular2-highcharts:’对象’类型上不存在属性’系列’

前端之家收集整理的这篇文章主要介绍了Typescript和Angular2-highcharts:’对象’类型上不存在属性’系列’前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
当我尝试在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: ...
            // ...
        };
    }
}

猜你在找的Angularjs相关文章