简体   繁体   中英

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. It does display the data but am getting this error 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.

Try replacing if (elem.confirmed) with if (elem.hasOwnProperty('confirmed'))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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