I am trying to delete a document and its nested documents in a collection inside the document in Firestore in Firebase using Angular. As of right now, I can delete said document and collection, but not without the compiler throwing an error at me error TS2339: Property 'id' does not exist on type '{}'. The error code might be right or wrong, I do honestly not know, as my code does find the id associated with the object I'm looking at. This is my code:
testID: string;
private testDoc: AngularFirestoreDocument<Test>;
constructor(private db: AngularFirestore) { }
deleteDoc() {
console.log('Deleting test');
this.db.collection(`tests/${this.testID}/questions`, ref => ref.orderBy('order'))
.valueChanges().subscribe(questions => {
questions.map(question => {
this.db.doc(`tests/${this.testID}/questions/${question.id}`).delete()
.catch(error => {console.log(error); })
.then(() => console.log(`tests/${this.testID}/questions/${question.id}`));
});
});
this.testDoc.delete().catch(error => console.log(error));
}
I have tried to pass 2 arguments in the map function as well but that just throws errors in the executed function instead of the compiler, thus making the code not work at all (I might not be passing the right thing here).
As I've mentioned, my code works, but I am most definitely doing something wrong. So my question is, what am I doing wrong to trigger a compile error and how do I avoid this while making sure the function still works? Hope someone can help clarify what it is I am doing wrong here.
Thank you in advance.
*Edit, included the doc I'm looking at
export interface Question {
description: string;
order: number;
type: string;
id: string;
name: string;
options?: Object[];
radio_amount?: number;
current_chips?: Object[];
imageURL?: string;
}