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

时间:2018-04-16 08:38:12

标签: javascript firebase angular5 google-cloud-firestore angularfire2

我编写了一个函数来检查云存储库中的文档中是否存在字段以显示数据,如果不存在则不应显示数据。它会显示数据,但收到此错误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)
            }
        })
    });
}

1 个答案:

答案 0 :(得分:0)

Typescript不知道element是什么类型,所以它抱怨。

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

相关问题