Skip to content

Enable noImplicitAny Typescript compiler flag #1862

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
Jun 17, 2019
Merged
1 change: 1 addition & 0 deletions config/tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"declaration": true,
"importHelpers": true,
"strictNullChecks": true,
"noImplicitAny": true,
"lib": [
"es2015",
"dom"
Expand Down
7 changes: 5 additions & 2 deletions packages/app/index.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@
import { FirebaseNamespace } from '@firebase/app-types';
import { _FirebaseNamespace } from '@firebase/app-types/private';
import { createFirebaseNamespace } from './src/firebaseNamespace';
import Storage from 'dom-storage';
import { XMLHttpRequest } from 'xmlhttprequest';
// Node specific packages.
// eslint-disable-next-line @typescript-eslint/no-require-imports
const Storage = require('dom-storage');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the motivation behind the change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dom-storage and xmlhttprequest don't have types so the type of Storage and XMLHttpRequest is implicitly any. Maybe it would be simpler to just @ts-ignore and explain it is a node package.

// eslint-disable-next-line @typescript-eslint/no-require-imports
const XMLHttpRequest = require('xmlhttprequest');

const _firebase = createFirebaseNamespace() as _FirebaseNamespace;

Expand Down
6 changes: 6 additions & 0 deletions packages/app/src/firebaseNamespaceCore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export function createFirebaseNamespaceCore(
//
// import * as firebase from 'firebase';
// which becomes: var firebase = require('firebase');
// @ts-ignore
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed, please cast to any and use eslint suppression instead of @ts-ignore.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

namespace['default'] = namespace;

// firebase.apps is a read-only getter.
Expand Down Expand Up @@ -108,6 +109,7 @@ export function createFirebaseNamespaceCore(
return apps[name];
}

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

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

// Forward service instance lookup to the FirebaseApp.
// @ts-ignore
return appArg[name]();
}

Expand All @@ -214,9 +218,11 @@ export function createFirebaseNamespaceCore(
}

// Monkey-patch the serviceNamespace onto the firebase namespace
// @ts-ignore
namespace[name] = serviceNamespace;

// Patch the FirebaseAppImpl prototype
// @ts-ignore
firebaseAppImpl.prototype[name] = function(...args) {
const serviceFxn = this._getService.bind(this, name);
return serviceFxn.apply(this, allowMultipleInstances ? args : []);
Expand Down
5 changes: 4 additions & 1 deletion packages/app/test/firebaseApp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,10 @@ function executeFirebaseLiteTests(): void {
});
}

function firebaseAppTests(testName, firebaseNamespaceFactory): void {
function firebaseAppTests(
testName: string,
firebaseNamespaceFactory: () => FirebaseNamespace
): void {
describe(testName, () => {
let firebase: FirebaseNamespace;

Expand Down
6 changes: 5 additions & 1 deletion packages/database/index.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ import * as types from '@firebase/database-types';

const ServerValue = Database.ServerValue;

export function initStandalone(app, url, version?: string) {
export function initStandalone(
app: FirebaseApp,
url: string,
version?: string
) {
/**
* This should allow the firebase-admin package to provide a custom version
* to the backend
Expand Down
13 changes: 8 additions & 5 deletions packages/database/src/core/PersistentConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -948,11 +948,14 @@ export class PersistentConnection extends ServerActions {

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

for (let i = 0; i < this.outstandingPuts_.length; i++) {
if (this.outstandingPuts_[i]) this.sendPut_(i);
Expand Down
4 changes: 2 additions & 2 deletions packages/database/src/core/snap/ChildrenNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ export class ChildrenNode implements Node {
val(exportFormat?: boolean): object {
if (this.isEmpty()) return null;

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

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

return array;
Expand Down
2 changes: 1 addition & 1 deletion packages/database/src/core/snap/IndexMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export class IndexMap {
// regular child map
return null;
} else {
return sortedMap;
return sortedMap as SortedMap<NamedNode, Node>;
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/database/src/core/snap/Node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export interface Node {
* @param {boolean=} exportFormat True for export format (also wire protocol format).
* @return {*} Value of this node as JSON.
*/
val(exportFormat?: boolean): Object;
val(exportFormat?: boolean): unknown;

/**
* @return {string} hash representing the node contents.
Expand Down
2 changes: 1 addition & 1 deletion packages/database/src/core/snap/nodeFromJSON.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export function nodeFromJSON(
}
} else {
let node: Node = ChildrenNode.EMPTY_NODE;
const jsonObj = json as object;
const jsonObj = json as { [key: string]: unknown };
forEach(jsonObj, (key: string, childData: any) => {
if (contains(jsonObj, key)) {
if (key.substring(0, 1) !== '.') {
Expand Down
3 changes: 2 additions & 1 deletion packages/database/src/core/snap/snap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ export const validatePriorityNode = function(priorityNode: Node) {
assert(
typeof val === 'string' ||
typeof val === 'number' ||
(typeof val === 'object' && contains(val, '.sv')),
(typeof val === 'object' &&
contains(val as { [key: string]: unknown }, '.sv')),
'Priority must be a string or number.'
);
} else {
Expand Down
12 changes: 6 additions & 6 deletions packages/database/src/core/util/CountedSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { isEmpty, getCount, forEach, contains } from '@firebase/util';
*
* @template K, V
*/
export class CountedSet<K, V> {
export class CountedSet<K extends string | number, V> {
set: { [k: string]: V } = {};

/**
Expand All @@ -38,7 +38,7 @@ export class CountedSet<K, V> {
* @return {boolean}
*/
contains(key: K) {
return contains(this.set, key);
return contains(this.set, key as string);
}

/**
Expand Down Expand Up @@ -82,8 +82,8 @@ export class CountedSet<K, V> {
* Run a function on each k,v pair in the set
* @param {function(K, V)} fn
*/
each(fn: (k: K, v: V) => void) {
forEach(this.set, (k: K, v: V) => fn(k, v));
each(fn: (k: K | string, v: V) => void) {
forEach(this.set, (k: string, v: V) => fn(k, v));
}

/**
Expand All @@ -92,8 +92,8 @@ export class CountedSet<K, V> {
*/
keys(): K[] {
const keys: K[] = [];
forEach(this.set, (k: K) => {
keys.push(k);
forEach(this.set, (k: string) => {
keys.push(k as K);
});
return keys;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/database/src/core/util/Tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class Tree<T> {
subTree(pathObj: string | Path): Tree<T> {
// TODO: Require pathObj to be Path?
let path = pathObj instanceof Path ? pathObj : new Path(pathObj);
let child = this as any,
let child = this as Tree<T>,
next;
while ((next = path.getFront()) !== null) {
const childNode = safeGet(child.node_.children, next) || new TreeNode();
Expand Down
3 changes: 2 additions & 1 deletion packages/database/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"extends": "../../config/tsconfig.base.json",
"compilerOptions": {
"outDir": "dist",
"strictNullChecks": false
"strictNullChecks": false,
"noImplicitAny": false
},
"exclude": [
"dist/**/*"
Expand Down
7 changes: 4 additions & 3 deletions packages/firestore/index.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@
*/

import firebase from '@firebase/app';
import './src/platform_node/node_init';
import { FirebaseNamespace } from '@firebase/app-types';
import * as types from '@firebase/firestore-types';
import { Firestore } from './src/api/database';
import { configureForFirebase } from './src/platform/config';
import * as types from '@firebase/firestore-types';
import './src/platform_node/node_init';

export function registerFirestore(instance) {
export function registerFirestore(instance: FirebaseNamespace): void {
configureForFirebase(instance);
}

Expand Down
5 changes: 3 additions & 2 deletions packages/firestore/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@
*/

import firebase from '@firebase/app';
import './src/platform_browser/browser_init';
import { FirebaseNamespace } from '@firebase/app-types';
import { Firestore } from './src/api/database';
import { configureForFirebase } from './src/platform/config';
import './src/platform_browser/browser_init';

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

export function registerFirestore(instance) {
export function registerFirestore(instance: FirebaseNamespace): void {
configureForFirebase(instance);
}

Expand Down
4 changes: 3 additions & 1 deletion packages/firestore/src/api/credentials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ export class FirstPartyToken implements Token {
constructor(private gapi: Gapi, private sessionIndex: string) {}

get authHeaders(): { [header: string]: string } {
const headers = {
const headers: { [header: string]: string } = {
'X-Goog-AuthUser': this.sessionIndex
};
const authHeader = this.gapi.auth.getAuthHeaderValueForFirstParty([]);
Expand Down Expand Up @@ -315,7 +315,9 @@ export function makeCredentialsProvider(
!!(
typeof client === 'object' &&
client !== null &&
// @ts-ignore
client['auth'] &&
// @ts-ignore
client['auth']['getAuthHeaderValueForFirstParty']
),
'unexpected gapi interface'
Expand Down
10 changes: 7 additions & 3 deletions packages/firestore/src/core/firestore_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ import { AutoId } from '../util/misc';
import { DatabaseId, DatabaseInfo } from './database_info';
import { Query } from './query';
import { Transaction } from './transaction';
import { OnlineStateSource } from './types';
import { OnlineState, OnlineStateSource } from './types';
import { ViewSnapshot } from './view_snapshot';

const LOG_TAG = 'FirestoreClient';
Expand Down Expand Up @@ -429,12 +429,16 @@ export class FirestoreClient {
serializer
);

const remoteStoreOnlineStateChangedHandler = onlineState =>
const remoteStoreOnlineStateChangedHandler = (
onlineState: OnlineState
) =>
this.syncEngine.applyOnlineStateChange(
onlineState,
OnlineStateSource.RemoteStore
);
const sharedClientStateOnlineStateChangedHandler = onlineState =>
const sharedClientStateOnlineStateChangedHandler = (
onlineState: OnlineState
) =>
this.syncEngine.applyOnlineStateChange(
onlineState,
OnlineStateSource.SharedClientState
Expand Down
4 changes: 3 additions & 1 deletion packages/firestore/src/core/sync_engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,9 @@ export class SyncEngine implements RemoteSyncer, SharedClientStateSyncer {
objUtils.forEach(
remoteEvent.targetChanges,
(targetId, targetChange) => {
const limboResolution = this.limboResolutionsByTarget[targetId];
const limboResolution = this.limboResolutionsByTarget[
Number(targetId)
];
if (limboResolution) {
// Since this is a limbo resolution lookup, it's for a single document
// and it could be added, modified, or removed, but not a combination.
Expand Down
12 changes: 9 additions & 3 deletions packages/firestore/src/local/indexeddb_mutation_queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -478,9 +478,15 @@ export class IndexedDbMutationQueue implements MutationQueue {
batch
).next(removedDocuments => {
this.removeCachedMutationKeys(batch.batchId);
return PersistencePromise.forEach(removedDocuments, key => {
return this.referenceDelegate.removeMutationReference(transaction, key);
});
return PersistencePromise.forEach(
removedDocuments,
(key: DocumentKey) => {
return this.referenceDelegate.removeMutationReference(
transaction,
key
);
}
);
});
}

Expand Down
12 changes: 8 additions & 4 deletions packages/firestore/src/local/indexeddb_persistence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ const ZOMBIED_CLIENTS_KEY_PREFIX = 'firestore_zombie';
export class IndexedDbTransaction extends PersistenceTransaction {
constructor(
readonly simpleDbTransaction: SimpleDbTransaction,
readonly currentSequenceNumber
readonly currentSequenceNumber: ListenSequenceNumber
) {
super();
}
Expand Down Expand Up @@ -515,8 +515,10 @@ export class IndexedDbPersistence implements Persistence {
})
.next(() =>
// Delete metadata for clients that are no longer considered active.
PersistencePromise.forEach(inactiveClients, inactiveClient =>
metadataStore.delete(inactiveClient.clientId)
PersistencePromise.forEach(
inactiveClients,
(inactiveClient: DbClientMetadata) =>
metadataStore.delete(inactiveClient.clientId)
)
)
.next(() => {
Expand Down Expand Up @@ -882,7 +884,9 @@ export class IndexedDbPersistence implements Persistence {
* Obtains or extends the new primary lease for the local client. This
* method does not verify that the client is eligible for this lease.
*/
private acquireOrExtendPrimaryLease(txn): PersistencePromise<void> {
private acquireOrExtendPrimaryLease(
txn: SimpleDbTransaction
): PersistencePromise<void> {
const newPrimary = new DbPrimaryClient(
this.clientId,
this.allowTabSynchronization,
Expand Down
2 changes: 1 addition & 1 deletion packages/firestore/src/local/indexeddb_query_cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ export class IndexedDbQueryCache implements QueryCache {
// PORTING NOTE: The reverse index (documentsTargets) is maintained by
// IndexedDb.
const store = documentTargetStore(txn);
return PersistencePromise.forEach(keys, key => {
return PersistencePromise.forEach(keys, (key: DocumentKey) => {
const path = EncodedResourcePath.encode(key.path);
return PersistencePromise.waitFor([
store.delete([targetId, path]),
Expand Down
Loading