2017-09-14 81 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: ... 
      // ... 
     }; 
    } 
} 
相關問題