类型"{}"上不存在属性"xxx"

编程入门 行业动态 更新时间:2024-10-26 17:25:12
本文介绍了类型"{}"上不存在属性"xxx"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我今天在我的角度应用程序中遇到了一种奇怪的行为.

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

因此,基本上,我订阅了一个可观察对象,并将数据从可观察对象映射到全局变量.我的角度应用程序按预期工作,因此此错误似乎对应用程序本身没有影响,但我仍然无法弄清这里出了什么问题.以下是data的控制台日志:

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"}

推荐答案

Typescript抱怨您在数据中没有该属性,您可以使用任何属性或使用该属性创建一个接口,

Typescript complains 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) => {

更多推荐

类型"{}"上不存在属性"xxx"

本文发布于:2023-10-20 09:09:18,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1510541.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:上不   属性   类型   xxx   quot

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!