首先,这对我没有帮助:property map does not exist并导入' rxjs'做nork
只需使用我的函数使用typescript并使用" async"和#34;等待"关键字由于某种原因我在尝试使用map时遇到错误是我的代码(顺便说一句,如果我使用&#34从firestore中恢复数据的方式;等待"不正确我会非常非常好,如果有人纠正我的话) - 无法找到很多使用typescript / functions / 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
的package.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
}
答案 0 :(得分:1)
await
将应用于map
的结果,您基本上是在致电:
const f = await (db.collection('companies').get().map(...))
您希望在等待map
的结果上调用get
,并且您应该添加括号以告诉编译器这是您想要做的事情。您也可能在快照上查找docs
属性(返回查询结果)
const f = (await db.collection('companies').get()).docs.map(...)