LoginSignup
0
0

More than 1 year has passed since last update.

Cloud Functions + TypeScriptでserviceAccountの設定で詰まった時のとてもシンプルな対処法

Posted at

結論: ServiceAccountの型を付与する

firebase.ts
import * as admin from 'firebase-admin';
import { ServiceAccount } from 'firebase-admin';
import serviceAccount from '../serviceAccountKey.json';

admin.initializeApp({
  credential: admin.credential.cert(serviceAccount as ServiceAccount),
 // 上に記したように `ServiceAccount`の型を与える
});

export const firestore = admin.firestore();

型を与えないと下記のようなエラーが表示されます

Argument of type '{ type: string; project_id: string; private_key_id: string; private_key: string; client_email: string; client_id: string; auth_uri: string; token_uri: string; auth_provider_x509_cert_url: string; client_x509_cert_url: string; }' is not assignable to parameter of type 'string | ServiceAccount'.
  Type '{ type: string; project_id: string; private_key_id: string; private_key: string; client_email: string; client_id: string; auth_uri: string; token_uri: string; auth_provider_x509_cert_url: string; client_x509_cert_url: string; }' has no properties in common with type 'ServiceAccount'.

ソース:
https://github.com/firebase/firebase-admin-node/issues/522
https://firebase.google.com/docs/reference/admin/node/admin.ServiceAccount

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0