Skip to content

Commit 611674c

Browse files
committed
noImplicitAny TS fixes
1 parent 7367b5f commit 611674c

File tree

96 files changed

+537
-458
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+537
-458
lines changed

config/.eslintrc.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
"**/test/**/*.ts"
2121
],
2222
"rules": {
23-
"no-unused-expressions": "off"
23+
"no-unused-expressions": "off",
24+
"@typescript-eslint/no-explicit-any": "off"
2425
}
2526
}
2627
],

packages/app/index.node.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@
1818
import { FirebaseNamespace } from '@firebase/app-types';
1919
import { _FirebaseNamespace } from '@firebase/app-types/private';
2020
import { createFirebaseNamespace } from './src/firebaseNamespace';
21-
import Storage from 'dom-storage';
22-
import { XMLHttpRequest } from 'xmlhttprequest';
21+
// Node specific packages.
22+
// eslint-disable-next-line @typescript-eslint/no-require-imports
23+
const Storage = require('dom-storage');
24+
// eslint-disable-next-line @typescript-eslint/no-require-imports
25+
const XMLHttpRequest = require('xmlhttprequest');
2326

2427
const _firebase = createFirebaseNamespace() as _FirebaseNamespace;
2528

packages/app/index.rn.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { createFirebaseNamespace } from './src/firebaseNamespace';
2424
* some of our tests because of duplicate symbols, we are using require syntax
2525
* here
2626
*/
27+
// eslint-disable-next-line
2728
const { AsyncStorage } = require('react-native');
2829

2930
const _firebase = createFirebaseNamespace() as _FirebaseNamespace;

packages/app/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ if (isBrowser() && 'firebase' in self) {
2929
Firebase library is only loaded once.
3030
`);
3131

32+
// eslint-disable-next-line
3233
const sdkVersion = ((self as any).firebase as FirebaseNamespace).SDK_VERSION;
3334
if (sdkVersion && sdkVersion.indexOf('LITE') >= 0) {
3435
logger.warn(`

packages/app/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"lint:fix": "eslint --fix -c .eslintrc.json '**/*.ts'",
1919
"build": "rollup -c",
2020
"dev": "rollup -c -w",
21-
"test": "run-p test:browser test:node",
21+
"test": "run-p lint test:browser test:node",
2222
"test:browser": "karma start --single-run",
2323
"test:browser:debug": "karma start --browsers Chrome --auto-watch",
2424
"test:node": "TS_NODE_CACHE=NO TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' nyc --reporter lcovonly -- mocha test/**/*.test.* --opts ../../config/mocha.node.opts",

packages/app/src/firebaseApp.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ interface ServicesCache {
3838

3939
// An array to capture listeners before the true auth functions
4040
// exist
41-
let tokenListeners: any[] = [];
41+
let tokenListeners: Array<(token: string | null) => void> = [];
4242

4343
/**
4444
* Global context object for a collection of services using
@@ -175,6 +175,7 @@ export class FirebaseAppImpl implements FirebaseApp {
175175
* Callback function used to extend an App instance at the time
176176
* of service instance creation.
177177
*/
178+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
178179
private extendApp(props: { [name: string]: any }): void {
179180
// Copy the object onto the FirebaseAppImpl prototype
180181
deepExtend(this, props);

packages/app/src/firebaseNamespace.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ export function createFirebaseNamespace(): FirebaseNamespace {
3232
const namespace = createFirebaseNamespaceCore(FirebaseAppImpl);
3333
(namespace as _FirebaseNamespace).INTERNAL = {
3434
...(namespace as _FirebaseNamespace).INTERNAL,
35-
createFirebaseNamespace: createFirebaseNamespace,
36-
extendNamespace: extendNamespace,
37-
createSubscribe: createSubscribe,
38-
ErrorFactory: ErrorFactory,
39-
deepExtend: deepExtend
35+
createFirebaseNamespace,
36+
extendNamespace,
37+
createSubscribe,
38+
ErrorFactory,
39+
deepExtend
4040
};
4141

4242
/**

packages/app/src/firebaseNamespaceCore.ts

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,13 @@ import {
2929
FirebaseServiceNamespace,
3030
AppHook
3131
} from '@firebase/app-types/private';
32-
import { deepExtend, patchProperty } from '@firebase/util';
32+
import { deepExtend, contains } from '@firebase/util';
3333
import { FirebaseAppImpl } from './firebaseApp';
3434
import { ERROR_FACTORY, AppError } from './errors';
3535
import { FirebaseAppLiteImpl } from './lite/firebaseAppLite';
3636
import { DEFAULT_ENTRY_NAME } from './constants';
3737
import { version } from '../../firebase/package.json';
3838

39-
function contains(obj: object, key: string) {
40-
return Object.prototype.hasOwnProperty.call(obj, key);
41-
}
42-
4339
/**
4440
* Because auth can't share code with other components, we attach the utility functions
4541
* in an internal namespace to share code.
@@ -60,9 +56,11 @@ export function createFirebaseNamespaceCore(
6056
// as the firebase namespace.
6157
// @ts-ignore
6258
__esModule: true,
63-
initializeApp: initializeApp,
64-
app: app as any,
65-
apps: null as any,
59+
initializeApp,
60+
// @ts-ignore
61+
app,
62+
// @ts-ignore
63+
apps: null,
6664
SDK_VERSION: version,
6765
INTERNAL: {
6866
registerService,
@@ -82,7 +80,8 @@ export function createFirebaseNamespaceCore(
8280
//
8381
// import * as firebase from 'firebase';
8482
// which becomes: var firebase = require('firebase');
85-
patchProperty(namespace, 'default', namespace);
83+
// @ts-ignore
84+
namespace['default'] = namespace;
8685

8786
// firebase.apps is a read-only getter.
8887
Object.defineProperty(namespace, 'apps', {
@@ -105,12 +104,13 @@ export function createFirebaseNamespaceCore(
105104
function app(name?: string): FirebaseApp {
106105
name = name || DEFAULT_ENTRY_NAME;
107106
if (!contains(apps, name)) {
108-
throw ERROR_FACTORY.create(AppError.NO_APP, { name: name });
107+
throw ERROR_FACTORY.create(AppError.NO_APP, { name });
109108
}
110109
return apps[name];
111110
}
112111

113-
patchProperty(app, 'App', firebaseAppImpl);
112+
// @ts-ignore
113+
app['App'] = firebaseAppImpl;
114114
/**
115115
* Create a new App instance (name must be unique).
116116
*/
@@ -119,7 +119,10 @@ export function createFirebaseNamespaceCore(
119119
config?: FirebaseAppConfig
120120
): FirebaseApp;
121121
function initializeApp(options: FirebaseOptions, name?: string): FirebaseApp;
122-
function initializeApp(options: FirebaseOptions, rawConfig = {}) {
122+
function initializeApp(
123+
options: FirebaseOptions,
124+
rawConfig = {}
125+
): FirebaseApp {
123126
if (typeof rawConfig !== 'object' || rawConfig === null) {
124127
const name = rawConfig;
125128
rawConfig = { name };
@@ -138,7 +141,7 @@ export function createFirebaseNamespaceCore(
138141
}
139142

140143
if (contains(apps, name)) {
141-
throw ERROR_FACTORY.create(AppError.DUPLICATE_APP, { name: name });
144+
throw ERROR_FACTORY.create(AppError.DUPLICATE_APP, { name });
142145
}
143146

144147
const app = new firebaseAppImpl(
@@ -177,7 +180,7 @@ export function createFirebaseNamespaceCore(
177180
): FirebaseServiceNamespace<FirebaseService> {
178181
// Cannot re-register a service that already exists
179182
if (factories[name]) {
180-
throw ERROR_FACTORY.create(AppError.DUPLICATE_SERVICE, { name: name });
183+
throw ERROR_FACTORY.create(AppError.DUPLICATE_SERVICE, { name });
181184
}
182185

183186
// Capture the service factory for later service instantiation
@@ -194,16 +197,18 @@ export function createFirebaseNamespaceCore(
194197
}
195198

196199
// The Service namespace is an accessor function ...
197-
function serviceNamespace(appArg: FirebaseApp = app()) {
200+
function serviceNamespace(appArg: FirebaseApp = app()): FirebaseService {
201+
// @ts-ignore
198202
if (typeof appArg[name] !== 'function') {
199203
// Invalid argument.
200204
// This happens in the following case: firebase.storage('gs:/')
201205
throw ERROR_FACTORY.create(AppError.INVALID_APP_ARGUMENT, {
202-
name: name
206+
name
203207
});
204208
}
205209

206210
// Forward service instance lookup to the FirebaseApp.
211+
// @ts-ignore
207212
return appArg[name]();
208213
}
209214

@@ -213,9 +218,11 @@ export function createFirebaseNamespaceCore(
213218
}
214219

215220
// Monkey-patch the serviceNamespace onto the firebase namespace
221+
// @ts-ignore
216222
namespace[name] = serviceNamespace;
217223

218224
// Patch the FirebaseAppImpl prototype
225+
// @ts-ignore
219226
firebaseAppImpl.prototype[name] = function(...args) {
220227
const serviceFxn = this._getService.bind(this, name);
221228
return serviceFxn.apply(this, allowMultipleInstances ? args : []);
@@ -224,7 +231,7 @@ export function createFirebaseNamespaceCore(
224231
return serviceNamespace;
225232
}
226233

227-
function callAppHooks(app: FirebaseApp, eventName: string) {
234+
function callAppHooks(app: FirebaseApp, eventName: string): void {
228235
for (const serviceName of Object.keys(factories)) {
229236
// Ignore virtual services
230237
const factoryName = useAsService(app, serviceName);

packages/app/src/lite/firebaseAppLite.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ export class FirebaseAppLiteImpl implements FirebaseApp {
157157
* Callback function used to extend an App instance at the time
158158
* of service instance creation.
159159
*/
160-
private extendApp(props: { [name: string]: any }): void {
160+
private extendApp(props: { [name: string]: unknown }): void {
161161
// Copy the object onto the FirebaseAppImpl prototype
162162
deepExtend(this, props);
163163
}

packages/app/src/lite/firebaseNamespaceLite.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ import {
2020
_FirebaseApp,
2121
_FirebaseNamespace,
2222
FirebaseServiceFactory,
23-
AppHook
23+
AppHook,
24+
FirebaseServiceNamespace,
25+
FirebaseService
2426
} from '@firebase/app-types/private';
2527
import { FirebaseAppLiteImpl } from './firebaseAppLite';
2628
import { createFirebaseNamespaceCore } from '../firebaseNamespaceCore';
@@ -41,10 +43,10 @@ export function createFirebaseNamespaceLite(): FirebaseNamespace {
4143
function registerServiceForLite(
4244
name: string,
4345
createService: FirebaseServiceFactory,
44-
serviceProperties?: { [prop: string]: any },
46+
serviceProperties?: { [prop: string]: unknown },
4547
appHook?: AppHook,
4648
allowMultipleInstances?: boolean
47-
) {
49+
): FirebaseServiceNamespace<FirebaseService> {
4850
// only allow performance to register with firebase lite
4951
if (name !== 'performance' && name !== 'installations') {
5052
throw Error(`${name} cannot register with the standalone perf instance`);

packages/app/test/firebaseApp.test.ts

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import { assert } from 'chai';
2828
executeFirebaseTests();
2929
executeFirebaseLiteTests();
3030

31-
function executeFirebaseTests() {
31+
function executeFirebaseTests(): void {
3232
firebaseAppTests('Firebase App Tests', createFirebaseNamespace);
3333

3434
describe('Firebase Service Registration', () => {
@@ -40,24 +40,24 @@ function executeFirebaseTests() {
4040
it('Register App Hook', done => {
4141
const events = ['create', 'delete'];
4242
let hookEvents = 0;
43-
let app: FirebaseApp;
4443
(firebase as _FirebaseNamespace).INTERNAL.registerService(
4544
'test',
4645
(app: FirebaseApp) => {
4746
return new TestService(app);
4847
},
4948
undefined,
50-
(event: string, app: FirebaseApp) => {
49+
(event: string, _app: FirebaseApp) => {
5150
assert.equal(event, events[hookEvents]);
5251
hookEvents += 1;
5352
if (hookEvents === events.length) {
5453
done();
5554
}
5655
}
5756
);
58-
app = firebase.initializeApp({});
57+
const app = firebase.initializeApp({});
5958
// Ensure the hook is called synchronously
6059
assert.equal(hookEvents, 1);
60+
// tslint:disable-next-line:no-floating-promises
6161
app.delete();
6262
});
6363

@@ -140,7 +140,7 @@ function executeFirebaseTests() {
140140
return new TestService(app);
141141
},
142142
undefined,
143-
(event: string, app: FirebaseApp) => {
143+
(event: string, _app: FirebaseApp) => {
144144
assert.equal(event, events[hookEvents]);
145145
hookEvents += 1;
146146
if (hookEvents === events.length) {
@@ -150,6 +150,7 @@ function executeFirebaseTests() {
150150
);
151151
// Ensure the hook is called synchronously
152152
assert.equal(hookEvents, 1);
153+
// tslint:disable-next-line:no-floating-promises
153154
app.delete();
154155
});
155156

@@ -221,6 +222,7 @@ function executeFirebaseTests() {
221222
);
222223
assert.strictEqual(service, service2);
223224
});
225+
224226
it(`Should pass null to the factory method if using default instance`, () => {
225227
// Register Multi Instance Service
226228
(firebase as _FirebaseNamespace).INTERNAL.registerService(
@@ -235,11 +237,8 @@ function executeFirebaseTests() {
235237
}
236238
);
237239
firebase.initializeApp({});
238-
239-
// Capture a given service ref
240-
const serviceIdentifier = 'custom instance identifier';
241-
const service = (firebase.app() as any).testService();
242240
});
241+
243242
it(`Should extend INTERNAL per app instance`, () => {
244243
let counter: number = 0;
245244
(firebase as _FirebaseNamespace).INTERNAL.registerService(
@@ -280,7 +279,7 @@ function executeFirebaseTests() {
280279
});
281280
}
282281

283-
function executeFirebaseLiteTests() {
282+
function executeFirebaseLiteTests(): void {
284283
firebaseAppTests('Firebase App Lite Tests', createFirebaseNamespaceLite);
285284

286285
describe('Firebase Lite Service Registration', () => {
@@ -291,14 +290,13 @@ function executeFirebaseLiteTests() {
291290
});
292291

293292
it('should allow Performance service to register', () => {
294-
let app: FirebaseApp;
295293
(firebase as _FirebaseNamespace).INTERNAL.registerService(
296294
'performance',
297295
(app: FirebaseApp) => {
298296
return new TestService(app);
299297
}
300298
);
301-
app = firebase.initializeApp({});
299+
const app = firebase.initializeApp({});
302300
const perf = (app as any).performance();
303301
assert.isTrue(perf instanceof TestService);
304302
});
@@ -316,7 +314,7 @@ function executeFirebaseLiteTests() {
316314
});
317315
}
318316

319-
function firebaseAppTests(testName, firebaseNamespaceFactory) {
317+
function firebaseAppTests(testName: string, firebaseNamespaceFactory: () => FirebaseNamespace): void {
320318
describe(testName, () => {
321319
let firebase: FirebaseNamespace;
322320

packages/database/index.node.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import * as types from '@firebase/database-types';
4040

4141
const ServerValue = Database.ServerValue;
4242

43-
export function initStandalone(app, url, version?: string) {
43+
export function initStandalone(app: FirebaseApp, url: string, version?: string) {
4444
/**
4545
* This should allow the firebase-admin package to provide a custom version
4646
* to the backend

packages/database/src/core/PersistentConnection.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -948,7 +948,7 @@ export class PersistentConnection extends ServerActions {
948948

949949
// Puts depend on having received the corresponding data update from the server before they complete, so we must
950950
// make sure to send listens before puts.
951-
forEach(this.listens_, (pathString: string, queries: Object) => {
951+
forEach(this.listens_, (pathString: string, queries: { [key: string]: ListenSpec }) => {
952952
forEach(queries, (key: string, listenSpec: ListenSpec) => {
953953
this.sendListen_(listenSpec);
954954
});

packages/database/src/core/snap/ChildrenNode.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ export class ChildrenNode implements Node {
201201
val(exportFormat?: boolean): object {
202202
if (this.isEmpty()) return null;
203203

204-
const obj: { [k: string]: Object } = {};
204+
const obj: { [k: string]: unknown } = {};
205205
let numKeys = 0,
206206
maxKey = 0,
207207
allIntegerKeys = true;
@@ -218,7 +218,7 @@ export class ChildrenNode implements Node {
218218

219219
if (!exportFormat && allIntegerKeys && maxKey < 2 * numKeys) {
220220
// convert to array.
221-
const array: Object[] = [];
221+
const array: unknown[] = [];
222222
for (let key in obj) array[(key as any) as number] = obj[key];
223223

224224
return array;

0 commit comments

Comments
 (0)