Skip to content

Commit 2187664

Browse files
committed
address comments
1 parent dab2486 commit 2187664

File tree

11 files changed

+36
-48
lines changed

11 files changed

+36
-48
lines changed

packages/analytics-types/index.d.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,3 +201,10 @@ export interface Promotion {
201201
id?: string;
202202
name?: string;
203203
}
204+
205+
206+
declare module '@firebase/component' {
207+
interface NameServiceMapping {
208+
'analytics': FirebaseAnalytics;
209+
}
210+
}

packages/analytics/index.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export function registerAnalytics(instance: _FirebaseNamespace): void {
6060
.getImmediate();
6161
return {
6262
logEvent: analytics.logEvent
63-
} as FirebaseAnalyticsInternal;
63+
};
6464
} catch (e) {
6565
throw ERROR_FACTORY.create(
6666
AnalyticsError.INTEROP_COMPONENT_REG_FAILED,
@@ -88,9 +88,3 @@ declare module '@firebase/app-types' {
8888
analytics(): FirebaseAnalytics;
8989
}
9090
}
91-
92-
declare module '@firebase/component' {
93-
interface NameServiceMapping {
94-
'analytics': FirebaseAnalytics;
95-
}
96-
}

packages/app-types/index.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,9 @@ export interface FirebaseNamespace {
101101
// The current SDK version.
102102
SDK_VERSION: string;
103103
}
104+
105+
declare module '@firebase/component' {
106+
interface NameServiceMapping {
107+
'app': FirebaseApp;
108+
}
109+
}

packages/app/index.node.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* limitations under the License.
1616
*/
1717

18-
import { FirebaseNamespace, FirebaseApp } from '@firebase/app-types';
18+
import { FirebaseNamespace } from '@firebase/app-types';
1919
import { _FirebaseNamespace } from '@firebase/app-types/private';
2020
import { firebase as _firebase } from './src/firebaseNamespace';
2121
// Node specific packages.
@@ -38,9 +38,3 @@ export const firebase = _firebase as FirebaseNamespace;
3838

3939
// eslint-disable-next-line import/no-default-export
4040
export default firebase;
41-
42-
declare module '@firebase/component' {
43-
interface NameServiceMapping {
44-
'app': FirebaseApp;
45-
}
46-
}

packages/app/index.rn.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* limitations under the License.
1616
*/
1717

18-
import { FirebaseNamespace, FirebaseApp } from '@firebase/app-types';
18+
import { FirebaseNamespace } from '@firebase/app-types';
1919
import { _FirebaseNamespace } from '@firebase/app-types/private';
2020
import { firebase as _firebase } from './src/firebaseNamespace';
2121
/**
@@ -38,9 +38,3 @@ export const firebase = _firebase as FirebaseNamespace;
3838

3939
// eslint-disable-next-line import/no-default-export
4040
export default firebase;
41-
42-
declare module '@firebase/component' {
43-
interface NameServiceMapping {
44-
'app': FirebaseApp;
45-
}
46-
}

packages/app/index.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* limitations under the License.
1616
*/
1717

18-
import { FirebaseNamespace, FirebaseApp } from '@firebase/app-types';
18+
import { FirebaseNamespace } from '@firebase/app-types';
1919
import { firebase as firebaseNamespace } from './src/firebaseNamespace';
2020
import { isNode, isBrowser } from '@firebase/util';
2121
import { logger } from './src/logger';
@@ -69,9 +69,3 @@ export const firebase = firebaseNamespace;
6969

7070
// eslint-disable-next-line import/no-default-export
7171
export default firebase;
72-
73-
declare module '@firebase/component' {
74-
interface NameServiceMapping {
75-
'app': FirebaseApp;
76-
}
77-
}

packages/app/src/firebaseApp.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ import { deepCopy } from '@firebase/util';
2929
import {
3030
ComponentContainer,
3131
Component,
32-
ComponentType
32+
ComponentType,
33+
Name
3334
} from '@firebase/component';
3435
import { AppError, ERROR_FACTORY } from './errors';
3536
import { DEFAULT_ENTRY_NAME } from './constants';
@@ -125,8 +126,7 @@ export class FirebaseAppImpl implements FirebaseApp {
125126
// getImmediate will always succeed because _getService is only called for registered components.
126127
return (
127128
(this.container
128-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
129-
.getProvider(name as any)
129+
.getProvider(name as Name)
130130
.getImmediate({
131131
identifier: instanceIdentifier
132132
}) as unknown) as FirebaseService

packages/component/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,6 @@ export {
2222
ComponentType,
2323
InstanceFactory,
2424
InstantiationMode,
25-
NameServiceMapping
25+
NameServiceMapping,
26+
Name
2627
} from './src/types';

packages/component/src/component_container.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { Name } from './types';
2323
* ComponentContainer that provides Providers for service name T, e.g. `auth`, `auth-internal`
2424
*/
2525
export class ComponentContainer {
26-
private readonly providers = new Map<string, Provider>();
26+
private readonly providers = new Map<string, Provider<Name>>();
2727

2828
constructor(private readonly name: string) {}
2929

@@ -76,7 +76,7 @@ export class ComponentContainer {
7676
return provider as Provider<T>;
7777
}
7878

79-
getProviders(): Provider[] {
79+
getProviders(): Array<Provider<Name>> {
8080
return Array.from(this.providers.values());
8181
}
8282
}

packages/component/src/provider.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ import { Component } from './component';
2323

2424
/**
2525
* Provider for instance for service name T, e.g. 'auth', 'auth-internal'
26-
* U is an alias for the type of the instance
26+
* NameServiceMapping[T] is an alias for the type of the instance
2727
*/
28-
export class Provider<T extends Name = Name, U = NameServiceMapping[T]> {
28+
export class Provider<T extends Name> {
2929
private component: Component<T> | null = null;
30-
private readonly instances: Map<string, U> = new Map();
31-
private readonly instancesDeferred: Map<string, Deferred<U>> = new Map();
30+
private readonly instances: Map<string, NameServiceMapping[T]> = new Map();
31+
private readonly instancesDeferred: Map<string, Deferred<NameServiceMapping[T]>> = new Map();
3232

3333
constructor(
3434
private readonly name: T,
@@ -39,12 +39,12 @@ export class Provider<T extends Name = Name, U = NameServiceMapping[T]> {
3939
* @param identifier A provider can provide mulitple instances of a service
4040
* if this.component.multipleInstances is true.
4141
*/
42-
get(identifier: string = DEFAULT_ENTRY_NAME): Promise<U> {
42+
get(identifier: string = DEFAULT_ENTRY_NAME): Promise<NameServiceMapping[T]> {
4343
// if multipleInstances is not supported, use the default name
4444
const normalizedIdentifier = this.normalizeInstanceIdentifier(identifier);
4545

4646
if (!this.instancesDeferred.has(normalizedIdentifier)) {
47-
const deferred = new Deferred<U>();
47+
const deferred = new Deferred<NameServiceMapping[T]>();
4848
this.instancesDeferred.set(normalizedIdentifier, deferred);
4949
// If the service instance is available, resolve the promise with it immediately
5050
const instance = this.getOrInitializeService(normalizedIdentifier);
@@ -64,12 +64,12 @@ export class Provider<T extends Name = Name, U = NameServiceMapping[T]> {
6464
* the service is not immediately available.
6565
* If optional is true, the method returns null if the service is not immediately available.
6666
*/
67-
getImmediate(options: { identifier?: string; optional: true }): U | null;
68-
getImmediate(options?: { identifier?: string; optional?: false }): U;
67+
getImmediate(options: { identifier?: string; optional: true }): NameServiceMapping[T] | null;
68+
getImmediate(options?: { identifier?: string; optional?: false }): NameServiceMapping[T];
6969
getImmediate(options?: {
7070
identifier?: string;
7171
optional?: boolean;
72-
}): U | null {
72+
}): NameServiceMapping[T] | null {
7373
const { identifier, optional } = {
7474
identifier: DEFAULT_ENTRY_NAME,
7575
optional: false,
@@ -147,13 +147,13 @@ export class Provider<T extends Name = Name, U = NameServiceMapping[T]> {
147147
return this.component != null;
148148
}
149149

150-
private getOrInitializeService(identifier: string): U | null {
150+
private getOrInitializeService(identifier: string): NameServiceMapping[T] | null {
151151
let instance = this.instances.get(identifier);
152152
if (!instance && this.component) {
153153
instance = this.component.instanceFactory(
154154
this.container,
155155
normalizeIdentifierForFactory(identifier)
156-
) as U;
156+
) as NameServiceMapping[T];
157157
this.instances.set(identifier, instance);
158158
}
159159

packages/component/src/types.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,7 @@ export interface Dictionary {
5656
* This interface will be extended by Firebase SDKs to provide service name and service type mapping.
5757
* It is used as a generic constraint to ensure type safety.
5858
*/
59-
export interface NameServiceMapping {
60-
'app': string;
61-
}
59+
export interface NameServiceMapping { }
6260

6361
export type Name = keyof NameServiceMapping;
6462
export type Service = NameServiceMapping[Name];

0 commit comments

Comments
 (0)