Skip to content

Commit 7866e22

Browse files
authored
Enable noImplicitAny Typescript compiler flag (#1862)
Updated all packages except database to use noImplicitAny Typescript compiler flag.
1 parent 9f109f8 commit 7866e22

File tree

98 files changed

+556
-361
lines changed

Some content is hidden

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

98 files changed

+556
-361
lines changed

config/tsconfig.base.json

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"declaration": true,
55
"importHelpers": true,
66
"strictNullChecks": true,
7+
"noImplicitAny": true,
78
"lib": [
89
"es2015",
910
"dom"

packages/app/index.node.ts

+4-1
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+
// Node specific packages.
22+
// @ts-ignore
2123
import Storage from 'dom-storage';
22-
import { XMLHttpRequest } from 'xmlhttprequest';
24+
// @ts-ignore
25+
import XMLHttpRequest from 'xmlhttprequest';
2326

2427
const _firebase = createFirebaseNamespace() as _FirebaseNamespace;
2528

packages/app/src/firebaseNamespaceCore.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ export function createFirebaseNamespaceCore(
8080
//
8181
// import * as firebase from 'firebase';
8282
// which becomes: var firebase = require('firebase');
83-
namespace['default'] = namespace;
83+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
84+
(namespace as any)['default'] = namespace;
8485

8586
// firebase.apps is a read-only getter.
8687
Object.defineProperty(namespace, 'apps', {
@@ -108,6 +109,7 @@ export function createFirebaseNamespaceCore(
108109
return apps[name];
109110
}
110111

112+
// @ts-ignore
111113
app['App'] = firebaseAppImpl;
112114
/**
113115
* Create a new App instance (name must be unique).
@@ -196,6 +198,7 @@ export function createFirebaseNamespaceCore(
196198

197199
// The Service namespace is an accessor function ...
198200
function serviceNamespace(appArg: FirebaseApp = app()): FirebaseService {
201+
// @ts-ignore
199202
if (typeof appArg[name] !== 'function') {
200203
// Invalid argument.
201204
// This happens in the following case: firebase.storage('gs:/')
@@ -205,6 +208,7 @@ export function createFirebaseNamespaceCore(
205208
}
206209

207210
// Forward service instance lookup to the FirebaseApp.
211+
// @ts-ignore
208212
return appArg[name]();
209213
}
210214

@@ -214,9 +218,11 @@ export function createFirebaseNamespaceCore(
214218
}
215219

216220
// Monkey-patch the serviceNamespace onto the firebase namespace
221+
// @ts-ignore
217222
namespace[name] = serviceNamespace;
218223

219224
// Patch the FirebaseAppImpl prototype
225+
// @ts-ignore
220226
firebaseAppImpl.prototype[name] = function(...args) {
221227
const serviceFxn = this._getService.bind(this, name);
222228
return serviceFxn.apply(this, allowMultipleInstances ? args : []);

packages/app/test/firebaseApp.test.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,10 @@ function executeFirebaseLiteTests(): void {
314314
});
315315
}
316316

317-
function firebaseAppTests(testName, firebaseNamespaceFactory): void {
317+
function firebaseAppTests(
318+
testName: string,
319+
firebaseNamespaceFactory: () => FirebaseNamespace
320+
): void {
318321
describe(testName, () => {
319322
let firebase: FirebaseNamespace;
320323

packages/database/index.node.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@ 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(
44+
app: FirebaseApp,
45+
url: string,
46+
version?: string
47+
) {
4448
/**
4549
* This should allow the firebase-admin package to provide a custom version
4650
* to the backend

packages/database/src/core/PersistentConnection.ts

+8-5
Original file line numberDiff line numberDiff line change
@@ -948,11 +948,14 @@ 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) => {
952-
forEach(queries, (key: string, listenSpec: ListenSpec) => {
953-
this.sendListen_(listenSpec);
954-
});
955-
});
951+
forEach(
952+
this.listens_,
953+
(pathString: string, queries: { [key: string]: ListenSpec }) => {
954+
forEach(queries, (key: string, listenSpec: ListenSpec) => {
955+
this.sendListen_(listenSpec);
956+
});
957+
}
958+
);
956959

957960
for (let i = 0; i < this.outstandingPuts_.length; i++) {
958961
if (this.outstandingPuts_[i]) this.sendPut_(i);

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

+2-2
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;

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export class IndexMap {
7575
// regular child map
7676
return null;
7777
} else {
78-
return sortedMap;
78+
return sortedMap as SortedMap<NamedNode, Node>;
7979
}
8080
}
8181

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ export interface Node {
119119
* @param {boolean=} exportFormat True for export format (also wire protocol format).
120120
* @return {*} Value of this node as JSON.
121121
*/
122-
val(exportFormat?: boolean): Object;
122+
val(exportFormat?: boolean): unknown;
123123

124124
/**
125125
* @return {string} hash representing the node contents.

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ export function nodeFromJSON(
113113
}
114114
} else {
115115
let node: Node = ChildrenNode.EMPTY_NODE;
116-
const jsonObj = json as object;
116+
const jsonObj = json as { [key: string]: unknown };
117117
forEach(jsonObj, (key: string, childData: any) => {
118118
if (contains(jsonObj, key)) {
119119
if (key.substring(0, 1) !== '.') {

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ export const validatePriorityNode = function(priorityNode: Node) {
4747
assert(
4848
typeof val === 'string' ||
4949
typeof val === 'number' ||
50-
(typeof val === 'object' && contains(val, '.sv')),
50+
(typeof val === 'object' &&
51+
contains(val as { [key: string]: unknown }, '.sv')),
5152
'Priority must be a string or number.'
5253
);
5354
} else {

packages/database/src/core/util/CountedSet.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { isEmpty, getCount, forEach, contains } from '@firebase/util';
2222
*
2323
* @template K, V
2424
*/
25-
export class CountedSet<K, V> {
25+
export class CountedSet<K extends string | number, V> {
2626
set: { [k: string]: V } = {};
2727

2828
/**
@@ -38,7 +38,7 @@ export class CountedSet<K, V> {
3838
* @return {boolean}
3939
*/
4040
contains(key: K) {
41-
return contains(this.set, key);
41+
return contains(this.set, key as string);
4242
}
4343

4444
/**
@@ -82,8 +82,8 @@ export class CountedSet<K, V> {
8282
* Run a function on each k,v pair in the set
8383
* @param {function(K, V)} fn
8484
*/
85-
each(fn: (k: K, v: V) => void) {
86-
forEach(this.set, (k: K, v: V) => fn(k, v));
85+
each(fn: (k: K | string, v: V) => void) {
86+
forEach(this.set, (k: string, v: V) => fn(k, v));
8787
}
8888

8989
/**
@@ -92,8 +92,8 @@ export class CountedSet<K, V> {
9292
*/
9393
keys(): K[] {
9494
const keys: K[] = [];
95-
forEach(this.set, (k: K) => {
96-
keys.push(k);
95+
forEach(this.set, (k: string) => {
96+
keys.push(k as K);
9797
});
9898
return keys;
9999
}

packages/database/src/core/util/Tree.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export class Tree<T> {
5757
subTree(pathObj: string | Path): Tree<T> {
5858
// TODO: Require pathObj to be Path?
5959
let path = pathObj instanceof Path ? pathObj : new Path(pathObj);
60-
let child = this as any,
60+
let child = this as Tree<T>,
6161
next;
6262
while ((next = path.getFront()) !== null) {
6363
const childNode = safeGet(child.node_.children, next) || new TreeNode();

packages/database/tsconfig.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
"extends": "../../config/tsconfig.base.json",
33
"compilerOptions": {
44
"outDir": "dist",
5-
"strictNullChecks": false
5+
"strictNullChecks": false,
6+
"noImplicitAny": false
67
},
78
"exclude": [
89
"dist/**/*"

packages/firestore/index.node.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@
1616
*/
1717

1818
import firebase from '@firebase/app';
19-
import './src/platform_node/node_init';
19+
import { FirebaseNamespace } from '@firebase/app-types';
20+
import * as types from '@firebase/firestore-types';
2021
import { Firestore } from './src/api/database';
2122
import { configureForFirebase } from './src/platform/config';
22-
import * as types from '@firebase/firestore-types';
23+
import './src/platform_node/node_init';
2324

24-
export function registerFirestore(instance) {
25+
export function registerFirestore(instance: FirebaseNamespace): void {
2526
configureForFirebase(instance);
2627
}
2728

packages/firestore/index.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@
1616
*/
1717

1818
import firebase from '@firebase/app';
19-
import './src/platform_browser/browser_init';
19+
import { FirebaseNamespace } from '@firebase/app-types';
2020
import { Firestore } from './src/api/database';
2121
import { configureForFirebase } from './src/platform/config';
22+
import './src/platform_browser/browser_init';
2223

2324
import * as types from '@firebase/firestore-types';
2425

25-
export function registerFirestore(instance) {
26+
export function registerFirestore(instance: FirebaseNamespace): void {
2627
configureForFirebase(instance);
2728
}
2829

packages/firestore/src/api/credentials.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ export class FirstPartyToken implements Token {
263263
constructor(private gapi: Gapi, private sessionIndex: string) {}
264264

265265
get authHeaders(): { [header: string]: string } {
266-
const headers = {
266+
const headers: { [header: string]: string } = {
267267
'X-Goog-AuthUser': this.sessionIndex
268268
};
269269
const authHeader = this.gapi.auth.getAuthHeaderValueForFirstParty([]);
@@ -309,8 +309,8 @@ export function makeCredentialsProvider(
309309

310310
switch (credentials.type) {
311311
case 'gapi':
312-
const client = credentials.client;
313-
// Make sure this is a Gapi client.
312+
const client = credentials.client as Gapi;
313+
// Make sure this really is a Gapi client.
314314
assert(
315315
!!(
316316
typeof client === 'object' &&
@@ -321,7 +321,7 @@ export function makeCredentialsProvider(
321321
'unexpected gapi interface'
322322
);
323323
return new FirstPartyCredentialsProvider(
324-
client as Gapi,
324+
client,
325325
credentials.sessionIndex || '0'
326326
);
327327

packages/firestore/src/core/firestore_client.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ import { AutoId } from '../util/misc';
6060
import { DatabaseId, DatabaseInfo } from './database_info';
6161
import { Query } from './query';
6262
import { Transaction } from './transaction';
63-
import { OnlineStateSource } from './types';
63+
import { OnlineState, OnlineStateSource } from './types';
6464
import { ViewSnapshot } from './view_snapshot';
6565

6666
const LOG_TAG = 'FirestoreClient';
@@ -429,12 +429,16 @@ export class FirestoreClient {
429429
serializer
430430
);
431431

432-
const remoteStoreOnlineStateChangedHandler = onlineState =>
432+
const remoteStoreOnlineStateChangedHandler = (
433+
onlineState: OnlineState
434+
) =>
433435
this.syncEngine.applyOnlineStateChange(
434436
onlineState,
435437
OnlineStateSource.RemoteStore
436438
);
437-
const sharedClientStateOnlineStateChangedHandler = onlineState =>
439+
const sharedClientStateOnlineStateChangedHandler = (
440+
onlineState: OnlineState
441+
) =>
438442
this.syncEngine.applyOnlineStateChange(
439443
onlineState,
440444
OnlineStateSource.SharedClientState

packages/firestore/src/core/sync_engine.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,9 @@ export class SyncEngine implements RemoteSyncer, SharedClientStateSyncer {
433433
objUtils.forEach(
434434
remoteEvent.targetChanges,
435435
(targetId, targetChange) => {
436-
const limboResolution = this.limboResolutionsByTarget[targetId];
436+
const limboResolution = this.limboResolutionsByTarget[
437+
Number(targetId)
438+
];
437439
if (limboResolution) {
438440
// Since this is a limbo resolution lookup, it's for a single document
439441
// and it could be added, modified, or removed, but not a combination.

packages/firestore/src/local/indexeddb_mutation_queue.ts

+9-3
Original file line numberDiff line numberDiff line change
@@ -476,9 +476,15 @@ export class IndexedDbMutationQueue implements MutationQueue {
476476
batch
477477
).next(removedDocuments => {
478478
this.removeCachedMutationKeys(batch.batchId);
479-
return PersistencePromise.forEach(removedDocuments, key => {
480-
return this.referenceDelegate.removeMutationReference(transaction, key);
481-
});
479+
return PersistencePromise.forEach(
480+
removedDocuments,
481+
(key: DocumentKey) => {
482+
return this.referenceDelegate.removeMutationReference(
483+
transaction,
484+
key
485+
);
486+
}
487+
);
482488
});
483489
}
484490

packages/firestore/src/local/indexeddb_persistence.ts

+8-4
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ const ZOMBIED_CLIENTS_KEY_PREFIX = 'firestore_zombie';
116116
export class IndexedDbTransaction extends PersistenceTransaction {
117117
constructor(
118118
readonly simpleDbTransaction: SimpleDbTransaction,
119-
readonly currentSequenceNumber
119+
readonly currentSequenceNumber: ListenSequenceNumber
120120
) {
121121
super();
122122
}
@@ -515,8 +515,10 @@ export class IndexedDbPersistence implements Persistence {
515515
})
516516
.next(() =>
517517
// Delete metadata for clients that are no longer considered active.
518-
PersistencePromise.forEach(inactiveClients, inactiveClient =>
519-
metadataStore.delete(inactiveClient.clientId)
518+
PersistencePromise.forEach(
519+
inactiveClients,
520+
(inactiveClient: DbClientMetadata) =>
521+
metadataStore.delete(inactiveClient.clientId)
520522
)
521523
)
522524
.next(() => {
@@ -882,7 +884,9 @@ export class IndexedDbPersistence implements Persistence {
882884
* Obtains or extends the new primary lease for the local client. This
883885
* method does not verify that the client is eligible for this lease.
884886
*/
885-
private acquireOrExtendPrimaryLease(txn): PersistencePromise<void> {
887+
private acquireOrExtendPrimaryLease(
888+
txn: SimpleDbTransaction
889+
): PersistencePromise<void> {
886890
const newPrimary = new DbPrimaryClient(
887891
this.clientId,
888892
this.allowTabSynchronization,

packages/firestore/src/local/indexeddb_query_cache.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ export class IndexedDbQueryCache implements QueryCache {
293293
// PORTING NOTE: The reverse index (documentsTargets) is maintained by
294294
// IndexedDb.
295295
const store = documentTargetStore(txn);
296-
return PersistencePromise.forEach(keys, key => {
296+
return PersistencePromise.forEach(keys, (key: DocumentKey) => {
297297
const path = EncodedResourcePath.encode(key.path);
298298
return PersistencePromise.waitFor([
299299
store.delete([targetId, path]),

0 commit comments

Comments
 (0)