Typescript and Firebase 9

Viewed 1593

I have been upgrading from Firebase 8 to Firebase 9 (modular web version) and have run into problems with Typescript compiler problems. The upgrade process is described here:

https://firebase.google.com/docs/web/modular-upgrade

Previously Firebase was imported and initialised thus:

import app from 'firebase/app';

const firebaseApp: firebase.app.App = firebase.initializeApp(options);

In Firebase 9, the recommended approach is to

import { initializeApp } from "firebase/app"

const firebaseApp = initializeApp({ /* config */ });

I want to give the const firebaseApp a typing as I did before. How do i do this?

I have also got lots of weird typing errors generated by the Typescript compiler that didn't happen with Firebase 8.

node_modules/@firebase/auth/dist/auth-exp-public.d.ts:1097:47 - error TS2748: Cannot access ambient const enums when the '--isolatedModules' flag is provided.

1097 static readonly FACEBOOK_SIGN_IN_METHOD = SignInMethod.FACEBOOK; ~~~~~~~~~~~~ How do I get rid of these? I deleted node_modules/@firebase and reinstalled firebase 9 but it made no difference.

1 Answers

For the FACEBOOK_SIGN_IN_METHOD error, I think you need to attach some code to here for us to debug. Firebsae has a huge change of how to require feature e.g. getAuth() instead of firebaseApp.auth

// v9

import { initializeApp, FirebaseApp } from "firebase/app"
import { getAuth } from "firebase/auth";

const firebaseApp: FirebaseApp = initializeApp({ /* config */ });
const auth = getAuth(firebaseApp)

// v8


import firebase from 'firebase/app';

const firebaseApp: firebase.app.App = firebase.initializeApp({});
firebaseApp.auth

Related