简体   繁体   English

类型“ {}”上不存在“已确认”属性

[英]Property 'confirmed' does not exist on type '{}'

I have written a function to check if a field exist in a document in cloud firestore to display the data, if not it should not display the data. 我编写了一个函数来检查Cloud Firestore中的文档中是否存在一个字段来显示数据,如果不存在,则该字段不应显示数据。 It does display the data but am getting this error error TS2339: Property 'confirmed' does not exist on type '{}'. 它确实显示数据,但出现此错误error TS2339: Property 'confirmed' does not exist on type '{}'.

dataCollection: any;
data: Observable<MycollectionDoc[]>
activatedUsers: any[];

constructor(
    private afs: AngularFirestore,
    private router: Router
) { }

ngOnInit() {
    this.activatedUsers = [];
    let x = this.afs.collection('mycollection').valueChanges();
    x.forEach(element => {
        element.forEach(elem => {
            console.log('My element', elem);
            if (elem.confirmed) {

                this.activatedUsers.push(elem);
                console.log(elem)
            }
        })
    });
}

Typescript does not know what type element is, so it complains. Typescript不知道什么是type element ,因此会抱怨。

Try replacing if (elem.confirmed) with if (elem.hasOwnProperty('confirmed')) 尝试将if (elem.confirmed)替换为if (elem.hasOwnProperty('confirmed'))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM