node.js - 节点,firebase 函数属性“地图”在“承诺”类型上不存在
问题描述
首先,这对我没有帮助:属性映射不存在并且导入“rxjs”也不起作用
只是在我的函数中使用 typescript 并使用“async”和“await”关键字由于某种原因我在尝试使用 map 时遇到错误这是我的代码(顺便说一句,如果我使用“await”从 firestore 检索数据的方式不正确如果有人纠正我,我会非常高兴)-找不到很多使用打字稿/函数/firestore的示例):
import * as functions from 'firebase-functions';
import * as admin from "firebase-admin";
admin.initializeApp(functions.config().firebase);
let db = admin.firestore();
export const helloWorld = functions.https.onRequest(
async (request, response) => {
try {
let t = await getEmployees()
response.send("yes");
} catch (e) {
response.send('no')
}
});
async function getEmployees(): Promise<any> {
try {
const f = await db.collection('companies').get().map(value => {
let id = value.id
return id;
})
} catch (e) {
return e;
}
}
打字稿版本 2.8.3
包.json:
{
"name": "functions",
"scripts": {
"lint": "tslint --project tsconfig.json",
"build": "tsc",
"serve": "npm run build && firebase serve --only functions",
"shell": "npm run build && firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"main": "lib/index.js",
"dependencies": {
"firebase-admin": "^5.12.0",
"firebase-functions": "^1.0.1"
},
"devDependencies": {
"tslint": "^5.8.0",
"typescript": "2.8.3"
},
"private": true
}
解决方案
await
将应用于 的结果map
,您实际上是在调用:
const f = await (db.collection('companies').get().map(...))
你想调用map
awaiting 的结果get
,你应该添加括号来告诉编译器这是你想要做的。此外,您可能正在寻找docs
快照上的属性(返回查询结果)
const f = (await db.collection('companies').get()).docs.map(...)
推荐阅读
- amazon-web-services - 在 GSI 上扫描与在 DynamoDB 中扫描整个表
- css - 如何设计带有圆边的垂直线?
- design-patterns - 线程安全单例设计模式的实现差异
- cloud - Mobicents/jdiameter 云环境部署
- g1ant - Visual Studio 没有模板 G1ANT.Robot 插件
- mysql - 如何消除mysql中的特定行
- owl-api - 使用 OWL API 解析内联函数式语法公理
- docker - 远程访问 Kubernetes 入口
- python - 重新装箱 python 数组
- r - 如何在绘图中添加带有 geom_line 的连续线