Skip to content

Commit 8001820

Browse files
committed
refactor(database): Add 'noImplicitAny' support
Adds support for the 'noImplicitAny' Typescript compiler option to the database implementation.
1 parent 6362b2b commit 8001820

File tree

10 files changed

+28
-26
lines changed

10 files changed

+28
-26
lines changed

src/database/api/Query.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ import { DataSnapshot } from './DataSnapshot';
2222

2323
let __referenceConstructor: new(repo: Repo, path: Path) => Query;
2424

25+
export interface SnapshotCallback {
26+
(a: DataSnapshot, b?: string): any
27+
}
28+
2529
/**
2630
* A Query represents a filter to be applied to a firebase location. This object purely represents the
2731
* query expression (and exposes our public API to build the query). The actual query logic is in ViewBase.js.
@@ -143,8 +147,8 @@ export class Query {
143147
* @param {Object=} context
144148
* @return {!function(DataSnapshot, string=)}
145149
*/
146-
on(eventType: string, callback: (a: DataSnapshot, b?: string) => any,
147-
cancelCallbackOrContext?: ((a: Error) => any) | Object, context?: Object): (a: DataSnapshot, b?: string) => any {
150+
on(eventType: string, callback: SnapshotCallback,
151+
cancelCallbackOrContext?: ((a: Error) => any) | Object, context?: Object): SnapshotCallback {
148152
validateArgCount('Query.on', 2, 4, arguments.length);
149153
validateEventType('Query.on', 1, eventType, false);
150154
validateCallback('Query.on', 2, callback, false);
@@ -178,7 +182,7 @@ export class Query {
178182
* @param {?Object} context
179183
* @protected
180184
*/
181-
onChildEvent(callbacks: { [k: string]: (a: DataSnapshot, b: string | null) => any },
185+
onChildEvent(callbacks: { [k: string]: SnapshotCallback },
182186
cancelCallback: ((a: Error) => any) | null, context: Object | null) {
183187
const container = new ChildEventRegistration(callbacks, cancelCallback, context);
184188
this.repo.addEventCallbackForQuery(this, container);
@@ -189,7 +193,7 @@ export class Query {
189193
* @param {(function(!DataSnapshot, ?string=))=} callback
190194
* @param {Object=} context
191195
*/
192-
off(eventType?: string, callback?: (a: DataSnapshot, b?: string | null) => any, context?: Object) {
196+
off(eventType?: string, callback?: SnapshotCallback, context?: Object) {
193197
validateArgCount('Query.off', 0, 3, arguments.length);
194198
validateEventType('Query.off', 1, eventType, true);
195199
validateCallback('Query.off', 2, callback, true);
@@ -218,10 +222,8 @@ export class Query {
218222
* @param context
219223
* @return {!firebase.Promise}
220224
*/
221-
once(eventType: string,
222-
userCallback?: (a: DataSnapshot, b?: string) => any,
223-
cancelOrContext?,
224-
context?: Object): Promise<DataSnapshot> {
225+
once(eventType: string, userCallback?: SnapshotCallback,
226+
cancelOrContext?: ((a: Error) => void) | Object, context?: Object): Promise<DataSnapshot> {
225227
validateArgCount('Query.once', 1, 4, arguments.length);
226228
validateEventType('Query.once', 1, eventType, false);
227229
validateCallback('Query.once', 2, userCallback, true);
@@ -379,7 +381,7 @@ export class Query {
379381
}
380382

381383
// Calling with no params tells us to start at the beginning.
382-
if (value == null) {
384+
if (value === undefined) {
383385
value = null;
384386
name = null;
385387
}

src/database/core/SyncTree.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ export class SyncTree {
521521
let queries: Query[] = [];
522522
if (maybeChildSyncPoint) {
523523
queries = queries.concat(
524-
maybeChildSyncPoint.getQueryViews().map(view=> view.getQuery())
524+
maybeChildSyncPoint.getQueryViews().map(view=> view.getQuery())
525525
);
526526
}
527527
forEach(childMap, function (key: string, childQueries: Query[]) {

src/database/core/snap/ChildrenNode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ export class ChildrenNode implements Node {
186186
// convert to array.
187187
const array: Object[] = [];
188188
for (let key in obj)
189-
array[key as any as number] = obj[key];
189+
array[<number><any>key as any as number] = obj[key];
190190

191191
return array;
192192
} else {

src/database/core/snap/childSet.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,15 @@ export const buildChildSet = function<K,V>(childList: NamedNode[],
6464
return null;
6565
} else if (length == 1) {
6666
namedNode = childList[low];
67-
key = keyFn ? keyFn(namedNode) : namedNode as any as K;
68-
return new LLRBNode(key, namedNode.node as any as V, LLRBNode.BLACK, null, null);
67+
key = keyFn ? keyFn(namedNode) : <K><any>namedNode as any as K;
68+
return new LLRBNode(key, <V><any>namedNode.node as any as V, LLRBNode.BLACK, null, null);
6969
} else {
7070
const middle = parseInt((length / 2 as any), 10) + low;
7171
const left = buildBalancedTree(low, middle);
7272
const right = buildBalancedTree(middle + 1, high);
7373
namedNode = childList[middle];
74-
key = keyFn ? keyFn(namedNode) : namedNode as any as K;
75-
return new LLRBNode(key, namedNode.node as any as V, LLRBNode.BLACK, left, right);
74+
key = keyFn ? keyFn(namedNode) : <K><any>namedNode as any as K;
75+
return new LLRBNode(key, <V><any>namedNode.node as any as V, LLRBNode.BLACK, left, right);
7676
}
7777
};
7878

@@ -87,8 +87,8 @@ export const buildChildSet = function<K,V>(childList: NamedNode[],
8787
index -= chunkSize;
8888
const childTree = buildBalancedTree(low + 1, high);
8989
const namedNode = childList[low];
90-
const key: K = keyFn ? keyFn(namedNode) : namedNode as any as K;
91-
attachPennant(new LLRBNode(key, namedNode.node as any as V, color, null, childTree));
90+
const key: K = keyFn ? keyFn(namedNode) : <K><any>namedNode as any as K;
91+
attachPennant(new LLRBNode(key, <V><any>namedNode.node as any as V, color, null, childTree));
9292
};
9393

9494
const attachPennant = function (pennant: LLRBNode<K, V>) {

src/database/core/util/util.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,9 +240,9 @@ export const warnAboutUnsupportedMethod = function (methodName: string) {
240240
*/
241241
export const isInvalidJSONNumber = function (data: any): boolean {
242242
return typeof data === 'number' &&
243-
(data != data || // NaN
244-
data == Number.POSITIVE_INFINITY ||
245-
data == Number.NEGATIVE_INFINITY);
243+
(data != data || // NaN
244+
data == Number.POSITIVE_INFINITY ||
245+
data == Number.NEGATIVE_INFINITY);
246246
};
247247

248248

src/database/core/view/ChildChangeAccumulator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export class ChildChangeAccumulator {
1818
type == Change.CHILD_CHANGED ||
1919
type == Change.CHILD_REMOVED, 'Only child changes supported for tracking');
2020
assert(childKey !== '.priority', 'Only non-priority child changes can be tracked.');
21-
const oldChange = safeGet(this.changeMap_, childKey) as Change;
21+
const oldChange = <Change>safeGet(this.changeMap_, childKey) as Change;
2222
if (oldChange) {
2323
const oldType = oldChange.type;
2424
if (type == Change.CHILD_ADDED && oldType == Change.CHILD_REMOVED) {

src/database/realtime/Connection.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ export class Connection {
199199

200200
private onSecondaryControl_(controlData: { [k: string]: any }) {
201201
if (MESSAGE_TYPE in controlData) {
202-
const cmd: string = controlData[MESSAGE_TYPE] as string;
202+
const cmd = <string>controlData[MESSAGE_TYPE] as string;
203203
if (cmd === SWITCH_ACK) {
204204
this.upgradeIfSecondaryHealthy_();
205205
} else if (cmd === CONTROL_RESET) {
@@ -292,7 +292,7 @@ export class Connection {
292292
private onControl_(controlData: { [k: string]: any }) {
293293
const cmd: string = requireKey(MESSAGE_TYPE, controlData);
294294
if (MESSAGE_DATA in controlData) {
295-
const payload: any = controlData[MESSAGE_DATA];
295+
const payload = controlData[MESSAGE_DATA];
296296
if (cmd === SERVER_HELLO) {
297297
this.onHandshake_(payload);
298298
} else if (cmd === END_TRANSMISSION) {

src/database/realtime/Transport.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export abstract class Transport {
5353

5454
abstract markConnectionHealthy(): void;
5555

56-
abstract markConnectionHealthy();
56+
abstract markConnectionHealthy(): void;
5757
}
5858

5959
export interface TransportConstructor {

src/database/realtime/TransportManager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export class TransportManager {
5151
if (isSkipPollConnection) {
5252
this.transports_ = [WebSocketConnection];
5353
} else {
54-
const transports = this.transports_ = [] as TransportConstructor[];
54+
const transports = this.transports_ = <TransportConstructor[]>[] as TransportConstructor[];
5555
each(TransportManager.ALL_TRANSPORTS, (i: number, transport: TransportConstructor) => {
5656
if (transport && transport['isAvailable']()) {
5757
transports.push(transport);

src/database/realtime/WebSocketConnection.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ export class WebSocketConnection implements Transport {
273273
handleIncomingFrame(mess: { [k: string]: any }) {
274274
if (this.mySock === null)
275275
return; // Chrome apparently delivers incoming packets even after we .close() the connection sometimes.
276-
const data: string = mess['data'] as string;
276+
const data = <string>mess['data'] as string;
277277
this.bytesReceived += data.length;
278278
this.stats_.incrementCounter('bytes_received', data.length);
279279

0 commit comments

Comments
 (0)