2017-09-14 75 views

回答

0

当您将其键入Object时,编译器不知道该属性series是否存在于this.options中。

为了克服这一点,你可以删除打字的财产(懒惰的出路):

class AppComponent { 

    options: any; 
} 

或者你可以让编译器通过直接分配给它这样this.options将推断物体的类型输入正确:

class AppComponent { 

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

或在接口定义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: ... 
      // ... 
     }; 
    } 
} 
相关问题