Skip to content

Commit 340ce5c

Browse files
authored
Create index.d.ts for firebase-exp compat packages (#4689)
1 parent b374636 commit 340ce5c

File tree

19 files changed

+10138
-17
lines changed

19 files changed

+10138
-17
lines changed

.changeset/config.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"firebase-namespace-integration-test",
1414
"firebase-firestore-integration-test",
1515
"firebase-messaging-integration-test",
16+
"firebase-compat-typings-test",
1617
"@firebase/app-exp",
1718
"@firebase/analytics-compat",
1819
"@firebase/analytics-exp",
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "firebase-compat-typings-test",
3+
"private": true,
4+
"version": "0.1.0",
5+
"scripts": {
6+
"test": "tsc",
7+
"test:ci": "node ../../scripts/run_tests_in_ci.js -s test"
8+
},
9+
"dependencies": {
10+
"firebase-exp": "0.900.19"
11+
},
12+
"devDependencies": {
13+
"typescript": "4.2.2"
14+
}
15+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"extends": "../../config/tsconfig.base.json",
3+
"compileOnSave": false,
4+
"compilerOptions": {
5+
"outDir": "dist"
6+
},
7+
"include": ["typings.ts"],
8+
"exclude": [
9+
"dist"
10+
]
11+
}

integration/compat-typings/typings.ts

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
/**
2+
* @license
3+
* Copyright 2021 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
import firebase from 'firebase-exp/compat';
19+
import { FirebaseAuth, User } from '@firebase/auth-types';
20+
import { FirebaseAnalytics } from '@firebase/analytics-types';
21+
import { FirebaseApp } from '@firebase/app-compat';
22+
import {
23+
FirebaseFirestore,
24+
DocumentReference,
25+
CollectionReference
26+
} from '@firebase/firestore-types';
27+
import { FirebaseFunctions } from '@firebase/functions-types';
28+
import { FirebaseInstallations } from '@firebase/installations-types';
29+
// Get type directly from messaging package, messaging-compat does not implement
30+
// the current messaging API.
31+
import { MessagingCompat } from '../../packages-exp/messaging-compat/src/messaging-compat';
32+
import { FirebasePerformance } from '@firebase/performance-types';
33+
import { RemoteConfig } from '@firebase/remote-config-types';
34+
import {
35+
FirebaseStorage,
36+
Reference as StorageReference
37+
} from '@firebase/storage-types';
38+
39+
/**
40+
* Test namespaced types from compat/index.d.ts against the types used in
41+
* implementation of the actual compat services. In almost all cases the services
42+
* implement types found in the corresponding -types package. The only exceptions
43+
* are
44+
* - messaging, which has changed its public API in the compat version
45+
* - app-compat, which defines its FirebaseApp type in its own package
46+
*/
47+
48+
const namespaced: {
49+
auth: firebase.auth.Auth;
50+
analytics: firebase.analytics.Analytics;
51+
app: firebase.app.App;
52+
firestore: firebase.firestore.Firestore;
53+
functions: firebase.functions.Functions;
54+
installations?: firebase.installations.Installations;
55+
messaging: firebase.messaging.Messaging;
56+
performance: firebase.performance.Performance;
57+
remoteConfig: firebase.remoteConfig.RemoteConfig;
58+
storage: firebase.storage.Storage;
59+
storageReference: firebase.storage.Reference;
60+
firestoreDocumentReference: firebase.firestore.DocumentReference;
61+
firestoreCollectionReference: firebase.firestore.CollectionReference;
62+
authUser: firebase.User;
63+
} = {
64+
auth: firebase.auth(),
65+
analytics: firebase.analytics(),
66+
app: firebase.initializeApp({}),
67+
firestore: firebase.firestore(),
68+
functions: firebase.functions(),
69+
installations: {} as firebase.installations.Installations,
70+
messaging: firebase.messaging(),
71+
performance: firebase.performance(),
72+
remoteConfig: firebase.remoteConfig(),
73+
storage: firebase.storage(),
74+
storageReference: {} as firebase.storage.Reference,
75+
firestoreDocumentReference: {} as firebase.firestore.DocumentReference,
76+
firestoreCollectionReference: {} as firebase.firestore.CollectionReference,
77+
authUser: {} as firebase.User
78+
};
79+
80+
const compatTypes: {
81+
auth: FirebaseAuth;
82+
analytics: FirebaseAnalytics;
83+
app: FirebaseApp;
84+
firestore: FirebaseFirestore;
85+
functions: FirebaseFunctions;
86+
installations?: FirebaseInstallations;
87+
messaging: MessagingCompat;
88+
performance: FirebasePerformance;
89+
remoteConfig: RemoteConfig;
90+
storage: FirebaseStorage;
91+
storageReference: StorageReference;
92+
firestoreDocumentReference: DocumentReference;
93+
firestoreCollectionReference: CollectionReference;
94+
authUser: User;
95+
} = {
96+
auth: namespaced.auth,
97+
analytics: namespaced.analytics,
98+
app: namespaced.app,
99+
firestore: namespaced.firestore,
100+
functions: namespaced.functions,
101+
installations: namespaced.installations,
102+
messaging: namespaced.messaging,
103+
performance: namespaced.performance,
104+
remoteConfig: namespaced.remoteConfig,
105+
storage: namespaced.storage,
106+
storageReference: namespaced.storageReference,
107+
firestoreDocumentReference: namespaced.firestoreDocumentReference,
108+
firestoreCollectionReference: namespaced.firestoreCollectionReference,
109+
authUser: namespaced.authUser
110+
};

packages-exp/app-compat/src/firebaseApp.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import { _FirebaseService, _FirebaseNamespace } from './types';
3333
import { Compat } from '@firebase/util';
3434

3535
// eslint-disable-next-line @typescript-eslint/naming-convention
36-
export interface _FirebaseApp extends Compat<_FirebaseAppExp> {
36+
export interface _FirebaseApp {
3737
/**
3838
* The (read-only) name (identifier) for this App. '[DEFAULT]' is the default
3939
* App.
@@ -59,7 +59,7 @@ export interface _FirebaseApp extends Compat<_FirebaseAppExp> {
5959
* Global context object for a collection of services using
6060
* a shared authentication state.
6161
*/
62-
export class FirebaseAppImpl implements _FirebaseApp {
62+
export class FirebaseAppImpl implements Compat<_FirebaseAppExp>, _FirebaseApp {
6363
private container: ComponentContainer;
6464

6565
constructor(

packages-exp/firebase-exp/compat/app/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
"main": "dist/index.cjs.js",
44
"browser": "dist/index.esm.js",
55
"module": "dist/index.esm.js",
6-
"typings": "dist/compat/app/index.d.ts"
6+
"typings": "../index.d.ts"
77
}
88

0 commit comments

Comments
 (0)