属性“type”不存在于类型“typeof import(“/node_modules/firebase-admin/lib/default-namespace”)'. ts(2339)

hyrbngr7  于 2023-08-07  发布在  其他
关注(0)|答案(1)|浏览(168)

我想从NodeJS(TypeScript)后端验证令牌。在文档中,他们这样提到,但这是在JavaScript中,我希望它在TypeScript

var admin = require("firebase-admin");

var serviceAccount = require("path/to/serviceAccountKey.json");

admin.initializeApp({
  credential: admin.credential.cert(serviceAccount)
});

字符串
我想在TypeScript中使用this blog,如下所示

import * as firebase from 'firebase-admin'
import * as serviceAccount from 'firebase-admin'

const params = {
  type: serviceAccount.type,
  projectId: serviceAccount.project_id,
  privateKeyId: serviceAccount.private_key_id,
  privateKey: serviceAccount.private_key,
  clientEmail: serviceAccount.client_email,
  clientId: serviceAccount.client_id,
  authUri: serviceAccount.auth_uri,
  tokenUri: serviceAccount.token_uri,
  authProviderX509CertUrl: serviceAccount.auth_provider_x509_cert_url,
  clientC509CertUrl: serviceAccount.client_x509_cert_url
}
   
firebase.initializeApp({
  credential: firebase.credential.cert(params),
})


但是我得到了这个错误,我怎么才能摆脱这个呢?

Property 'type' does not exist on type 'typeof import("nodeFirebasebackend/node_modules/firebase-admin/lib/default-namespace")'.ts(2339)


的数据

kognpnkq

kognpnkq1#

查看https://firebase.google.com/docs/reference/admin/node/firebase-admin.serviceaccount上的文档
我可以看到serviceAccount具有以下属性:

  • clientEmail
  • privateKey
  • projectId

因此,您试图引用不存在的字段。

相关问题