gpt4 book ai didi

typescript - Firebase @google-cloud/firestore 包 typescript 错误重复标识符 'DocumentData'

转载 作者:搜寻专家 更新时间:2023-10-30 21:15:47 24 4
gpt4 key购买 nike

我正在使用 Typescript 使用 firebase 云函数,一切正常。在我的代码中,我创建了 DocumentReferenceGeoPoint 类型的变量之一,这就是使 vs 代码导入它

从“@google-cloud/firestore”导入 { GeoPoint, DocumentReference }

function offsetSlightly(location:GeoPoint) {
//some code here
return new GeoPoint(latitude, longitude)
}

所以我需要添加我使用命令添加的节点模块

npm install @google-cloud/firestore

当我尝试部署时,一切看起来都很好,我得到了很多重复的标识符,例如 DocumentData、UpdateData、GeoPoint 等

错误:

node_modules/firebase-admin/node_modules/@google-cloud/firestore/types/firestore.d.ts:28:15 - error TS2300: Duplicate identifier 'DocumentData'.


28 export type DocumentData = {[field: string]: any};

那是我的 package.json{

  "name": "functions",
"scripts": {
"lint": "tslint --project tsconfig.json",
"build": "tsc",
"serve": "npm run build && firebase serve --only functions",
"shell": "npm run build && firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"main": "lib/index.js",
"dependencies": {
"@google-cloud/firestore": "^0.14.1",
"firebase-admin": "^5.12.1",
"firebase-functions": "^1.0.4",
"nodemailer": "^4.6.4",
"twilio": "^3.16.0"
},
"devDependencies": {
"tslint": "^5.10.0",
"typescript": "^2.9.2"
},
"private": true
}

我不知道问题所在,但我认为这是包中的一些冲突。我是 android 开发人员,在 Node.js 方面有一点经验。有帮助吗?

最佳答案

不是从独立的 Firestore SDK 导入类,而是在 Firebase Admin SDK 的 Firestore 上创建类型别名:

import * as admin from 'firebase-admin';

type GeoPoint = admin.firestore.GeoPoint
type DocumentReference = admin.firestore.DocumentReference

关于typescript - Firebase @google-cloud/firestore 包 typescript 错误重复标识符 'DocumentData',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50947258/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com