Currently, I am enclosing my calls to Firebase within a function so that I can specify the return type within the function. This allows me to define the type of data being retrieved from a document. However, TypeScript complains if you do not convert the Firebase call to 'unknown' before converting it into the desired interface. Is there a more efficient way to accomplish this?
For example:
async function getAllPartials() {
const partialDocs = await db.collection('partials').get();
return partialDocs.docs.map(d => d.data()) as unknown as Array<Partial>;
}
I also attempted the following approach:
async function getAllPartials() {
const partialDocs = await db.collection<Partial>('partials').get();
return partialDocs.docs.map(d => d.data());
}
This resulted in an error message stating: "Expected 0 type arguments but got 1;"