Skip to content

Narrow some types #2298

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 1 commit into from
Oct 29, 2019
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
6 changes: 3 additions & 3 deletions packages/analytics/src/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,11 @@ export function factory(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
extendApp: (props: { [prop: string]: any }) => void
): FirebaseAnalytics {
if (!app.options[ANALYTICS_ID_FIELD]) {
const analyticsId = app.options[ANALYTICS_ID_FIELD];
if (!analyticsId) {
throw ERROR_FACTORY.create(AnalyticsError.NO_GA_ID);
}

const analyticsId: string = app.options[ANALYTICS_ID_FIELD];
if (initializedIdPromisesMap[analyticsId] != null) {
throw ERROR_FACTORY.create(AnalyticsError.ALREADY_EXISTS, {
id: analyticsId
Expand Down Expand Up @@ -159,7 +159,7 @@ export function factory(
setUserProperties: (properties, options) =>
setUserProperties(wrappedGtagFunction, analyticsId, properties, options),
setAnalyticsCollectionEnabled: enabled =>
setAnalyticsCollectionEnabled(app.options[ANALYTICS_ID_FIELD], enabled)
setAnalyticsCollectionEnabled(analyticsId, enabled)
};

extendApp({
Expand Down
2 changes: 1 addition & 1 deletion packages/analytics/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export async function initializeGAId(

// It should be the first config command called on this GA-ID
// Initialize this GA-ID and set FID on it using the gtag config API.
gtagCore(GtagCommand.CONFIG, app.options[ANALYTICS_ID_FIELD], {
gtagCore(GtagCommand.CONFIG, app.options[ANALYTICS_ID_FIELD]!, {
[GA_FID_KEY]: fid,
// guard against developers accidentally setting properties with prefix `firebase_`
[ORIGIN_KEY]: 'firebase',
Expand Down
2 changes: 1 addition & 1 deletion packages/app-types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export type FirebaseOptions = {
storageBucket?: string;
messagingSenderId?: string;
appId?: string;
[name: string]: any;
measurementId?: string;
};

export interface FirebaseAppConfig {
Expand Down
23 changes: 15 additions & 8 deletions packages/app/test/firebaseApp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@
* limitations under the License.
*/

import { FirebaseApp, FirebaseNamespace } from '@firebase/app-types';
import {
FirebaseApp,
FirebaseNamespace,
FirebaseOptions
} from '@firebase/app-types';
import {
_FirebaseApp,
_FirebaseNamespace,
Expand Down Expand Up @@ -414,9 +418,9 @@ function firebaseAppTests(
});

it('Can get options of App.', () => {
const options = { test: 'option' };
const options: FirebaseOptions = { projectId: 'projectId' };
const app = firebase.initializeApp(options);
assert.deepEqual(app.options as any, options as any);
assert.deepEqual(app.options, options);
});

it('Can delete App.', () => {
Expand Down Expand Up @@ -473,13 +477,16 @@ function firebaseAppTests(
});

it('Modifying options object does not change options.', () => {
const options = { opt: 'original', nested: { opt: 123 } };
const options: FirebaseOptions = {
appId: 'original',
measurementId: 'someId'
};
firebase.initializeApp(options);
options.opt = 'changed';
options.nested.opt = 456;
options.appId = 'changed';
delete options.measurementId;
assert.deepEqual(firebase.app().options, {
opt: 'original',
nested: { opt: 123 }
appId: 'original',
measurementId: 'someId'
});
});

Expand Down
3 changes: 1 addition & 2 deletions packages/installations/src/helpers/extract-app-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ export function extractAppConfig(app: FirebaseApp): AppConfig {

for (const keyName of configKeys) {
if (!app.options[keyName]) {
// Cast required becase FirebaseOptions includes "[name: string]: any;".
throw getMissingValueError(keyName as string);
throw getMissingValueError(keyName);
}
}

Expand Down
6 changes: 2 additions & 4 deletions packages/storage/src/implementation/authwrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { requestMaker } from './requestmaker';
import { RequestMap } from './requestmap';
import * as type from './type';
import { XhrIoPool } from './xhriopool';
import { FirebaseApp } from '@firebase/app-types';
import { FirebaseApp, FirebaseOptions } from '@firebase/app-types';
import {
_FirebaseApp,
FirebaseAuthTokenData
Expand Down Expand Up @@ -74,9 +74,7 @@ export class AuthWrapper {
this.requestMap_ = new RequestMap();
}

private static extractBucket_(config: {
[prop: string]: string;
}): string | null {
private static extractBucket_(config: FirebaseOptions): string | null {
const bucketString = config[constants.CONFIG_STORAGE_BUCKET_KEY] || null;
if (bucketString == null) {
return null;
Expand Down
10 changes: 5 additions & 5 deletions packages/storage/src/implementation/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,29 @@
/**
* Domain name for firebase storage.
*/
export const DEFAULT_HOST: string = 'firebasestorage.googleapis.com';
export const DEFAULT_HOST = 'firebasestorage.googleapis.com';

/**
* The key in Firebase config json for the storage bucket.
*/
export const CONFIG_STORAGE_BUCKET_KEY: string = 'storageBucket';
export const CONFIG_STORAGE_BUCKET_KEY = 'storageBucket';

/**
* 2 minutes
*
* The timeout for all operations except upload.
*/
export const DEFAULT_MAX_OPERATION_RETRY_TIME: number = 2 * 60 * 1000;
export const DEFAULT_MAX_OPERATION_RETRY_TIME = 2 * 60 * 1000;

/**
* 10 minutes
*
* The timeout for upload.
*/
export const DEFAULT_MAX_UPLOAD_RETRY_TIME: number = 10 * 60 * 1000;
export const DEFAULT_MAX_UPLOAD_RETRY_TIME = 10 * 60 * 1000;

/**
* This is the value of Number.MIN_SAFE_INTEGER, which is not well supported
* enough for us to use it directly.
*/
export const MIN_SAFE_INTEGER: number = -9007199254740991;
export const MIN_SAFE_INTEGER = -9007199254740991;