[英]Property 'confirmed' does not exist on type '{}'
我編寫了一個函數來檢查Cloud Firestore中的文檔中是否存在一個字段來顯示數據,如果不存在,則該字段不應顯示數據。 它確實顯示數據,但出現此錯誤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不知道什么是type element
,因此會抱怨。
嘗試將if (elem.confirmed)
替換為if (elem.hasOwnProperty('confirmed'))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.