Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Typescript and Angular2-highcharts: Property 'series' does not exist on type 'Object'

When i try to implement the following plunkr in Angular, i get the following error message.

Property 'series' does not exist on type 'Object'.

http://plnkr.co/edit/OQSFSKisIIWAH0megy4d?p=preview

i've installed "angular2-highcharts": "^0.5.5", and the typing "@types/highcharts": "^5.0.5",

Any help would be appreciated.

like image 902
Andreas Hald Avatar asked Sep 14 '17 09:09

Andreas Hald


1 Answers

The the compiler does not know if the property series is present in this.options when you type it as Object.

To overcome this you can either remove the typing for the property (the lazy way out):

class AppComponent {

    options: any;
}

Or you can let the compiler infer the type from the object by assigning it directly so this.options will be typed properly:

class AppComponent {

    options = {
        chart: {
            zoomType: 'xy'
        },
        series: ...
        // ...
    };
}

Or define the type of options in an interface:

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: ...
            // ...
        };
    }
}
like image 129
Saravana Avatar answered Nov 06 '22 12:11

Saravana