【发布时间】:2019-07-25 01:08:00
【问题描述】:
我正在使用 TypeScript 编写我的 Firebase 云函数。在我的代码中,我需要引用诸如 CollectionReference、QuerySnapshot 等 Firestore 数据类型。例如:
export const Employee: CollectionReference = admin.firestore().collection('Master/Admin/Employees');
or
async function convertToCsv(snapshot: QueryDocumentSnapshot[])
要在我的代码中使用这些类型,我在文件 (.ts) 的顶部使用以下行:
import { QueryDocumentSnapshot, Timestamp, Query, CollectionReference } from '@google-cloud/firestore';
当我在我的 PC 上本地运行 firebase 功能时,此代码可以正常工作,使用:
firebase serve --only 函数
但是当我尝试在我的 firebase 服务器上部署相同的代码时,我收到以下 tslint 错误并且代码部署失败。
Module '@google-cloud/firestore' is not listed as dependency in package.json
如果我在 package.json 中添加依赖项
"dependencies": {
"body-parser": "^1.18.3",
...
"@google-cloud/firestore": "~1.0.1"
},
我的函数已部署,但在执行时出现以下错误:
Error: Argument "value" is not a valid QueryValue. Detected an object of type "Timestamp" that doesn't match the expected instance. Please ensure that the Firestore types you are using are from the same NPM package.
at Validator.(anonymous function).err [as isQueryValue] (/user_code/node_modules/firebase-admin/node_modules/@google-cloud/firestore/build/src/validate.js:93:27)
at Query.where (/user_code/node_modules/firebase-admin/node_modules/@google-cloud/firestore/build/src/reference.js:916:25)
at /user_code/lib/services/reports/index.js:53:22
编译失败的java脚本行是(见**):
const firestore_1 = require("@google-cloud/firestore");
let query = collection
.where('divisionCode', '==', divisionCode)
**.where('zzLastUpdateOn', '>=', firestore_1.Timestamp.fromDate(startDate))**
.where('zzLastUpdateOn', '<=', firestore_1.Timestamp.fromDate(endDate))
.where('zzIsDeleted', '==', false);
我真的不知道在这里做什么,请帮忙。请知道我对 TypeScript 和 JavaScript 世界很陌生。
请知道,我在时间戳字段中添加值的同一项目中的其他功能工作正常。并且此功能在桌面(本地主机)的云功能模拟模式下也能正常工作。
您的帮助将不胜感激!!!
【问题讨论】:
标签: google-cloud-firestore google-cloud-functions