admin管理员组文章数量:1316371
I run into a strange behavior in my angular app today.
ERROR in src/main(A,B): error TS2339: Property 'XXX' does not exist on type '{}'.
The error occured at the following line of code
xxx.subscribe(data => {
this.var = data.XXX
});
So basically i subscribe to an observable and map the data from the observable to an global var. My angular App works as intended, so this error seems to have no effect on the app itself, but I still can't figure out whats wrong here. Below is the console log of data
:
console.log(data)
//{"XXX": "test"}
I run into a strange behavior in my angular app today.
ERROR in src/main(A,B): error TS2339: Property 'XXX' does not exist on type '{}'.
The error occured at the following line of code
xxx.subscribe(data => {
this.var = data.XXX
});
So basically i subscribe to an observable and map the data from the observable to an global var. My angular App works as intended, so this error seems to have no effect on the app itself, but I still can't figure out whats wrong here. Below is the console log of data
:
console.log(data)
//{"XXX": "test"}
Share
Improve this question
edited Jul 17, 2018 at 8:59
Niladri Basu
10.6k7 gold badges57 silver badges64 bronze badges
asked Jul 17, 2018 at 8:57
sHamannsHamann
7993 gold badges11 silver badges36 bronze badges
2
-
what if you use
data['XXX']
instead ? type{}
does not holdXXX
attribute, that's why. – Florian Commented Jul 17, 2018 at 8:59 - Possible duplicate of Property '_body' does not exist on type 'Response' – koninos Commented Dec 14, 2018 at 13:06
2 Answers
Reset to default 6Typescript plains that you do not have the property inside the data, you can either use any or create an inteface with that property,
xxx.subscribe((data:any) => {...}
You have instantiated data as just an object example : data = {}
.
As object doesn't have XXX
property it gives this error.
So solution will be data: {XXX: string, YYY: number ....} = {}
Else you can access XXX with data['XXX']
which is the easiest option
本文标签: javascriptProperty 39xxx39 does not exist on type 3939Stack Overflow
版权声明:本文标题:javascript - Property 'xxx' does not exist on type '{}' - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742002785a2411355.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论