将Firestore依赖项和类型导入到node.js [英] Import Firestore dependencies and types to node.js

查看:81
本文介绍了将Firestore依赖项和类型导入到node.js的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在今年的FirebaseSummit会谈之后,我最近将我的云函数更新为TypeScript.

I'm recently updating my cloud functions to TypeScript after the talks on the FirebaseSummit of this year.

我的所有代码看起来都很酷,但是尝试恢复Firestore API的类型时遇到了一些问题,例如QuerySnapshotDocumentReference ...

All my code looks quite cool, but I'm having some problems trying to recover the types of Firestore API, such 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;
}

现在,我的IDE(WebStorm)尚未获取FirebaseFirestore的类型.这是我的package.json的样子:

Right now my IDE (WebStorm) is not getting the types for FirebaseFirestore. This is how my package.json looks:

{
  "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
}

我已经尝试添加 @ firebase-firestore ,什么也没有,不工作.实现此目标的正确依赖是什么?

I have already tried to add @firebase-firestore and nothing, it's not working. What is the right dependency to achieve this?

推荐答案

我终于明白了! firebase-admin模块只是一个简单的包装程序,可为您初始化Firestore.要获得真正的Firestore,请将"@google-cloud/firestore": "^0.9.0"添加到您的package.json中.您可以在这里欣赏那些漂亮的类型: https://github .com/googleapis/nodejs-firestore/blob/master/types/firestore.d.ts .

I finally figured it out! The firebase-admin module is just a simple wrapper that initializes Firestore for you. To get the real Firestore, add "@google-cloud/firestore": "^0.9.0" to your package.json. You can admire those beautiful types here: https://github.com/googleapis/nodejs-firestore/blob/master/types/firestore.d.ts.

这篇关于将Firestore依赖项和类型导入到node.js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆