【发布时间】:2018-10-05 18:07:38
【问题描述】:
首先这对我没有帮助:property map does not exist 和导入 'rxjs' 也不起作用
只是使用带有我的函数的打字稿进行测试,并出于某种原因使用“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
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
}
【问题讨论】:
标签: node.js typescript google-cloud-firestore google-cloud-functions