gpt4 book ai didi

angular - Typescript 中的对象类型不存在属性

转载 作者:太空狗 更新时间:2023-10-29 18:05:23 24 4
gpt4 key购买 nike

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

Error: Error at /home/invicta/Desktop/newauth/.tmp/pages/dashboard/dashboard.ts:36:34 
Property 'notifications' does not exist on type '{}'

//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;
})
}

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

//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);
});
});
}

最佳答案

尝试绕过错误:

this._notifications = data['notifications'];

关于angular - Typescript 中的对象类型不存在属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40513703/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com