Skip to content

Create index.d.ts for firebase-exp compat packages #4689

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Apr 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .changeset/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"firebase-namespace-integration-test",
"firebase-firestore-integration-test",
"firebase-messaging-integration-test",
"firebase-compat-typings-test",
"@firebase/app-exp",
"@firebase/analytics-compat",
"@firebase/analytics-exp",
Expand Down
15 changes: 15 additions & 0 deletions integration/compat-typings/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "firebase-compat-typings-test",
"private": true,
"version": "0.1.0",
"scripts": {
"test": "tsc",
"test:ci": "node ../../scripts/run_tests_in_ci.js -s test"
},
"dependencies": {
"firebase-exp": "0.900.19"
},
"devDependencies": {
"typescript": "4.2.2"
}
}
11 changes: 11 additions & 0 deletions integration/compat-typings/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "../../config/tsconfig.base.json",
"compileOnSave": false,
"compilerOptions": {
"outDir": "dist"
},
"include": ["typings.ts"],
"exclude": [
"dist"
]
}
110 changes: 110 additions & 0 deletions integration/compat-typings/typings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/**
* @license
* Copyright 2021 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import firebase from 'firebase-exp/compat';
import { FirebaseAuth, User } from '@firebase/auth-types';
import { FirebaseAnalytics } from '@firebase/analytics-types';
import { FirebaseApp } from '@firebase/app-compat';
import {
FirebaseFirestore,
DocumentReference,
CollectionReference
} from '@firebase/firestore-types';
import { FirebaseFunctions } from '@firebase/functions-types';
import { FirebaseInstallations } from '@firebase/installations-types';
// Get type directly from messaging package, messaging-compat does not implement
// the current messaging API.
import { MessagingCompat } from '../../packages-exp/messaging-compat/src/messaging-compat';
import { FirebasePerformance } from '@firebase/performance-types';
import { RemoteConfig } from '@firebase/remote-config-types';
import {
FirebaseStorage,
Reference as StorageReference
} from '@firebase/storage-types';

/**
* Test namespaced types from compat/index.d.ts against the types used in
* implementation of the actual compat services. In almost all cases the services
* implement types found in the corresponding -types package. The only exceptions
* are
* - messaging, which has changed its public API in the compat version
* - app-compat, which defines its FirebaseApp type in its own package
*/

const namespaced: {
auth: firebase.auth.Auth;
analytics: firebase.analytics.Analytics;
app: firebase.app.App;
firestore: firebase.firestore.Firestore;
functions: firebase.functions.Functions;
installations?: firebase.installations.Installations;
messaging: firebase.messaging.Messaging;
performance: firebase.performance.Performance;
remoteConfig: firebase.remoteConfig.RemoteConfig;
storage: firebase.storage.Storage;
storageReference: firebase.storage.Reference;
firestoreDocumentReference: firebase.firestore.DocumentReference;
firestoreCollectionReference: firebase.firestore.CollectionReference;
authUser: firebase.User;
} = {
auth: firebase.auth(),
analytics: firebase.analytics(),
app: firebase.initializeApp({}),
firestore: firebase.firestore(),
functions: firebase.functions(),
installations: {} as firebase.installations.Installations,
messaging: firebase.messaging(),
performance: firebase.performance(),
remoteConfig: firebase.remoteConfig(),
storage: firebase.storage(),
storageReference: {} as firebase.storage.Reference,
firestoreDocumentReference: {} as firebase.firestore.DocumentReference,
firestoreCollectionReference: {} as firebase.firestore.CollectionReference,
authUser: {} as firebase.User
};

const compatTypes: {
auth: FirebaseAuth;
analytics: FirebaseAnalytics;
app: FirebaseApp;
firestore: FirebaseFirestore;
functions: FirebaseFunctions;
installations?: FirebaseInstallations;
messaging: MessagingCompat;
performance: FirebasePerformance;
remoteConfig: RemoteConfig;
storage: FirebaseStorage;
storageReference: StorageReference;
firestoreDocumentReference: DocumentReference;
firestoreCollectionReference: CollectionReference;
authUser: User;
} = {
auth: namespaced.auth,
analytics: namespaced.analytics,
app: namespaced.app,
firestore: namespaced.firestore,
functions: namespaced.functions,
installations: namespaced.installations,
messaging: namespaced.messaging,
performance: namespaced.performance,
remoteConfig: namespaced.remoteConfig,
storage: namespaced.storage,
storageReference: namespaced.storageReference,
firestoreDocumentReference: namespaced.firestoreDocumentReference,
firestoreCollectionReference: namespaced.firestoreCollectionReference,
authUser: namespaced.authUser
};
4 changes: 2 additions & 2 deletions packages-exp/app-compat/src/firebaseApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import { _FirebaseService, _FirebaseNamespace } from './types';
import { Compat } from '@firebase/util';

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

constructor(
Expand Down
2 changes: 1 addition & 1 deletion packages-exp/firebase-exp/compat/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"main": "dist/index.cjs.js",
"browser": "dist/index.esm.js",
"module": "dist/index.esm.js",
"typings": "dist/compat/app/index.d.ts"
"typings": "../index.d.ts"
}

Loading