【发布时间】:2019-05-05 14:02:09
【问题描述】:
我正在尝试将以下函数放入 .ts 文件中:
function incrementCounter(db, ref, num_shards) {
// Select a shard of the counter at random
const shard_id = Math.floor(Math.random() * num_shards).toString();
const shard_ref = ref.collection('shards').doc(shard_id);
// Update count
return shard_ref.update("count", firebase.firestore.FieldValue.increment(1));
}
此功能来自官方firestore文档:https://firebase.google.com/docs/firestore/solutions/counters
但我收到此错误:
类型“typeof FieldValue”上不存在属性“增量”.ts(2339)
我应该在我的项目中添加一些类型定义吗? 我对 ts 不熟悉,所以我很感激任何帮助。
附言我的 react-native 项目似乎仍在编译和部署,但我想摆脱这个错误。
编辑:
tsconfig.json -> 我的项目中没有这个配置文件。
npm ls | grep 火库
@firebase/firestore@0.5.3
│ │ ├── @firebase/firestore-types@0.4.2
导入语句:
import React from 'react';
import * as firebase from 'firebase';
import 'firebase/firestore';
【问题讨论】:
-
请确保您使用的是最新版本的 SDK/NPM 模块。上次我收到此错误消息时,我很难更新所有依赖项,因为其中一些依赖项已固定。
标签: typescript google-cloud-firestore