I am currently facing an issue with loading my Collection of Employees from a Firestore Database and fetching a 'Workday' for each Employee, which is stored as a Document in a Subcollection named 'Employees'. Below is the code snippet I am working with:
loadEmployees() {
return new Promise<Employee[]>(resolve => {
this.db.collection('Employees').snapshotChanges().pipe(
map(changes => changes.map(async a => {
const employee = a.payload.doc.data() as Employee;
employee.id = a.payload.doc.id;
employee.workday = await this.loadWorkday(employee); // <-- returns a Promise<Workday>
return employee;
}))
).subscribe(
employees => {
resolve(employees); // Error: <--- Promise<Employee>[]' is not assignable to parameter of type 'Employee[]
}
);
});
}
However, I am encountering a Syntax Error stating
Promise<Employee>[]' is not assignable to parameter of type 'Employee[]
. I am unsure how to obtain the Employee[]
from the Promise<Employee>[]
so that I can call the resolve function.