在Typescript中的Object类型中不存在属性

Jos*_*ker 3 promise typescript ionic2 angular

所以我使用Ionic和Angular2 Typescript.当呈现View时,我retrieveNotifications在文件中调用函数,dashboard.ts但是我收到错误:

Error: Error at /home/invicta/Desktop/newauth/.tmp/pages/dashboard/dashboard.ts:36:34 
Property 'notifications' does not exist on type '{}'
Run Code Online (Sandbox Code Playgroud)

这里还有一个截图:https://www.dropbox.com/s/6x2myxqm2q4dhzb/Screenshot%202016-11-09%2019.29.52.png?dl=0


//dashboard.ts
ionViewDidEnter(){
    this.retrieveNotifications();
  }


retrieveNotifications() {
  this.user.retrieveNotifications().then(data => {
    // when do console.log here and typeof(), data is object and it has notifications array
    this._notifications = data.notifications;
  })
}
Run Code Online (Sandbox Code Playgroud)

然后在文件user-data.ts中声明为public user:UserData是function:

//user-data.ts -> provider
retrieveNotifications(){
        var token = this.authservice.getUserToken();
        return new Promise(resolve => {
            var headers = new Headers();
            headers.append('Authorization', 'Bearer ' + token);
            this.http.get(this.mainUrl + '/api/v1/notification', {headers: headers}).subscribe(data => {
                if(data.status === 200)
                    resolve(data.json());
                else
                    resolve(false);
            });
        });
    }
Run Code Online (Sandbox Code Playgroud)

Avr*_*gil 10

尝试绕过错误:

this._notifications = data['notifications'];
Run Code Online (Sandbox Code Playgroud)