Fra*_*cia 3 node.js firebase typescript google-cloud-functions google-cloud-firestore
在今年 FirebaseSummit 的演讲之后,我最近将我的云函数更新为 TypeScript。
我所有的代码看起来都很酷,但是我在尝试恢复 Firestore API 的类型时遇到了一些问题,例如QuerySnapshot,DocumentReference...
async function getEventsMadeByUser(userId: string): Promise<FirebaseFirestore.DocumentSnapshot[]> {
const eventsMadeByUserQuery = await instance.collection('PrivateUserData')
.doc(userId).collection(EVENTS)
.where('interactionUser', '==', userId).get();
return eventsMadeByUserQuery.docs;
}
Run Code Online (Sandbox Code Playgroud)
现在我的 IDE (WebStorm) 没有获取FirebaseFirestore. 这是我的package.json样子:
{
"name": "functions",
"description": "Cloud Functions for Firebase",
"dependencies": {
"firebase-admin": "^5.4.3",
"firebase-functions": "^0.7.2"
},
"devDependencies": {
"@types/express": "^4.0.37",
"typescript": "^2.3.2"
},
"scripts": {
"build": "tsc",
"watch": "tsc --watch",
"deploy": "tsc && firebase deploy --only functions"
},
"main": "build/index.js",
"private": true
}
Run Code Online (Sandbox Code Playgroud)
我已经尝试添加@firebase-firestore,但没有任何效果,它不起作用。实现这一目标的正确依赖是什么?
我终于想通了!该firebase-admin模块只是一个简单的包装器,可为您初始化 Firestore。要获得真正的 Firestore,请添加"@google-cloud/firestore": "^0.9.0"到您的package.json. 您可以在这里欣赏这些漂亮的类型:https : //github.com/googleapis/nodejs-firestore/blob/master/types/firestore.d.ts。
| 归档时间: |
|
| 查看次数: |
2190 次 |
| 最近记录: |