Kim*_*Kim 4 firebase typescript tslint google-cloud-firestore
阅读最新的Firebase博客文章为什么你应该使用TypeScript编写云函数,我决定尝试tslint
它,这很神奇,虽然我的类型有问题.
我有一个import语句
import { DocumentSnapshot, DocumentReference, QuerySnapshot, WriteResult, Transaction, WriteBatch } from '@google-cloud/firestore';
Run Code Online (Sandbox Code Playgroud)
但即使我的代码工作正常,tslint告诉我以下内容.
[tslint]模块'@ google-cloud/firestore'未在package.json中列为依赖项(no-implicit-dependencies)
Firebase + TypeScript使用/导入类型的最佳做法是什么?
Dou*_*son 10
如果您希望能够从模块导入某些定义,则必须将该模块声明为依赖项.它们出现在您的package.json
文件中functions
.如果您希望能够从中导入@google-cloud/firestore
,则需要添加依赖项:
npm install @google-cloud/firestore
Run Code Online (Sandbox Code Playgroud)
现在,您可能想知道为什么在不声明依赖性的情况下可以使用Firestore.这是因为Firebase Admin SDK对Firestore SDK有自己的依赖性.因此,当您直接使用Admin SDK时,您可以访问Firestore SDK创建的对象.但是,如果您没有自己声明依赖项,则您自己的模块无法直接从中导入.
我同意接受的答案。
而不是安装@google-cloud/firestore
。您可以使用admin.firestore.QuerySnapshot
,admin.firestore.DocumentSnapshot
等等。
这是更好的方法。您可以使用此访问所有内容。
归档时间: |
|
查看次数: |
2248 次 |
最近记录: |