11import { InjectionToken , NgZone , NgModule , Optional } from '@angular/core' ;
2+ import { app , auth , apps , database , firestore , functions , initializeApp , messaging , storage } from 'firebase/app' ;
23
3- import { FirebaseOptionsToken , FirebaseNameOrConfigToken } from './angularfire2' ;
4+ // Public types don't expose FirebaseOptions or FirebaseAppConfig
5+ export type FirebaseOptions = { [ key :string ] : any } ;
6+ export type FirebaseAppConfig = { [ key :string ] : any } ;
47
5- import firebase from '@firebase/app' ;
6- import { FirebaseApp as _FirebaseApp , FirebaseOptions , FirebaseAppConfig } from '@firebase/app-types' ;
7- import { FirebaseAuth } from '@firebase/auth-types' ;
8- import { FirebaseDatabase } from '@firebase/database-types' ;
9- import { FirebaseMessaging } from '@firebase/messaging-types' ;
10- import { FirebaseStorage } from '@firebase/storage-types' ;
11- import { FirebaseFirestore } from '@firebase/firestore-types' ;
12- import { FirebaseFunctions } from '@firebase/functions-types' ;
8+ export const FirebaseOptionsToken = new InjectionToken < FirebaseOptions > ( 'angularfire2.app.options' ) ;
9+ export const FirebaseNameOrConfigToken = new InjectionToken < string | FirebaseAppConfig | undefined > ( 'angularfire2.app.nameOrConfig' )
1310
14- export class FirebaseApp implements _FirebaseApp {
11+ export type FirebaseDatabase = database . Database ;
12+ export type FirebaseAuth = auth . Auth ;
13+ export type FirebaseMessaging = messaging . Messaging ;
14+ export type FirebaseStorage = storage . Storage ;
15+ export type FirebaseFirestore = firestore . Firestore ;
16+ export type FirebaseFunctions = functions . Functions ;
17+
18+ export class FirebaseApp implements app . App {
1519 name : string ;
16- automaticDataCollectionEnabled : boolean ;
1720 options : { } ;
1821 auth : ( ) => FirebaseAuth ;
22+ // app.App database() doesn't take a databaseURL arg in the public types?
1923 database : ( databaseURL ?: string ) => FirebaseDatabase ;
24+ // automaticDataCollectionEnabled is now private? _automaticDataCollectionEnabled?
25+ // automaticDataCollectionEnabled: true,
2026 messaging : ( ) => FirebaseMessaging ;
2127 storage : ( storageBucket ?: string ) => FirebaseStorage ;
2228 delete : ( ) => Promise < void > ;
@@ -28,8 +34,9 @@ export function _firebaseAppFactory(options: FirebaseOptions, nameOrConfig?: str
2834 const name = typeof nameOrConfig === 'string' && nameOrConfig || '[DEFAULT]' ;
2935 const config = typeof nameOrConfig === 'object' && nameOrConfig || { } ;
3036 config . name = config . name || name ;
31- const existingApp = firebase . apps . filter ( app => app . name === config . name ) [ 0 ] ;
32- return ( existingApp || firebase . initializeApp ( options , config ) ) as FirebaseApp ;
37+ const existingApp = apps . filter ( app => app && app . name === config . name ) [ 0 ] ;
38+ // We support FirebaseConfig, initializeApp's public type only accepts string; need to cast as any
39+ return ( existingApp || ( initializeApp as any ) ( options , config ) ) as FirebaseApp ;
3340}
3441
3542const FirebaseAppProvider = {
0 commit comments