【发布时间】:2020-02-04 20:53:04
【问题描述】:
我有一个类似的功能:
async queryAll(): Promise<Product[]> {
const response = await this.firestore.collection('products').get();
return response.docs.map(a => a.data());
}
得到错误:
类型“DocumentData[]”不可分配给类型“Product[]”。类型 “DocumentData”缺少类型中的以下属性 “产品”:ID、名称
如何为此方法添加正确的返回类型?
我在firebase/index.ts.d、get 函数类型中可以看到什么(我使用的是 npm firebase 包):
get(options?: GetOptions): Promise<QuerySnapshot<T>>;
但不确定如何将其应用于我的代码。
【问题讨论】:
标签: typescript firebase google-cloud-firestore