Skip to content

Commit bcb006f

Browse files
danielasylaurenzlong
authored andcommitted
Disallow implicit any typings (noImplicitAny: true) (#215)
1 parent d26ec60 commit bcb006f

18 files changed

+55
-53
lines changed

spec/apps.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ describe('apps', () => {
4242
});
4343

4444
describe('retain/release', () => {
45-
let clock;
45+
let clock: sinon.SinonFakeTimers;
4646

4747
beforeEach(() => {
4848
clock = sinon.useFakeTimers();

spec/cloud-functions.spec.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222

2323
import * as _ from 'lodash';
2424
import { expect } from 'chai';
25-
import { Event, LegacyEvent, makeCloudFunction, MakeCloudFunctionArgs, Change } from '../src/cloud-functions';
25+
import { Event, EventContext, LegacyEvent,
26+
makeCloudFunction, MakeCloudFunctionArgs, Change } from '../src/cloud-functions';
2627

2728
describe('makeCloudFunction', () => {
2829
const cloudFunctionArgs: MakeCloudFunctionArgs<any> = {
@@ -45,7 +46,7 @@ describe('makeCloudFunction', () => {
4546
});
4647

4748
it('should construct the right context for legacy event format', () => {
48-
let args: any = _.assign({}, cloudFunctionArgs, {handler: (data, context) => context});
49+
let args: any = _.assign({}, cloudFunctionArgs, {handler: (data: any, context: EventContext) => context});
4950
let cf = makeCloudFunction(args);
5051
let test: LegacyEvent = {
5152
eventId: '00000',
@@ -68,7 +69,7 @@ describe('makeCloudFunction', () => {
6869
});
6970

7071
it('should construct the right context for new event format', () => {
71-
let args: any = _.assign({}, cloudFunctionArgs, { handler: (data, context) => context });
72+
let args: any = _.assign({}, cloudFunctionArgs, { handler: (data: any, context: EventContext) => context });
7273
let cf = makeCloudFunction(args);
7374
let test: Event = {
7475
context: {
@@ -277,9 +278,9 @@ describe('Change', () => {
277278
});
278279

279280
it('should apply the customizer function to `before` and `after`', () => {
280-
function customizer<T>(input) {
281+
function customizer<T>(input: any) {
281282
_.set(input, 'another', 'value');
282-
return input;
283+
return input as T;
283284
}
284285
let created = Change.fromJSON<Object>(
285286
{

spec/providers/auth.spec.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import * as auth from '../../src/providers/auth';
2424
import { expect } from 'chai';
2525
import * as firebase from 'firebase-admin';
26+
import { CloudFunction } from '../../src';
2627

2728
describe('Auth Functions', () => {
2829
describe('AuthBuilder', () => {
@@ -63,9 +64,9 @@ describe('Auth Functions', () => {
6364
});
6465

6566
describe('#_dataConstructor', () => {
66-
let cloudFunctionCreate;
67-
let cloudFunctionDelete;
68-
let event;
67+
let cloudFunctionCreate: CloudFunction<firebase.auth.UserRecord>;
68+
let cloudFunctionDelete: CloudFunction<firebase.auth.UserRecord>;
69+
let event: any;
6970

7071
before(() => {
7172
cloudFunctionCreate = auth.user().onCreate((data: firebase.auth.UserRecord) => data);
@@ -82,11 +83,11 @@ describe('Auth Functions', () => {
8283

8384
it('should transform wire format for UserRecord into v5.0.0 format', () => {
8485
return Promise.all([
85-
cloudFunctionCreate(event).then(data => {
86+
cloudFunctionCreate(event).then((data: any) => {
8687
expect(data.metadata.creationTime).to.equal('2016-12-15T19:37:37.059Z');
8788
expect(data.metadata.lastSignInTime).to.equal('2017-01-01T00:00:00.000Z');
8889
}),
89-
cloudFunctionDelete(event).then(data => {
90+
cloudFunctionDelete(event).then((data: any) => {
9091
expect(data.metadata.creationTime).to.equal('2016-12-15T19:37:37.059Z');
9192
expect(data.metadata.lastSignInTime).to.equal('2017-01-01T00:00:00.000Z');
9293
}),
@@ -104,11 +105,11 @@ describe('Auth Functions', () => {
104105
};
105106

106107
return Promise.all([
107-
cloudFunctionCreate(newEvent).then(data => {
108+
cloudFunctionCreate(newEvent).then((data: any) => {
108109
expect(data.metadata.creationTime).to.equal('2016-12-15T19:37:37.059Z');
109110
expect(data.metadata.lastSignInTime).to.equal('2017-01-01T00:00:00.000Z');
110111
}),
111-
cloudFunctionDelete(newEvent).then(data => {
112+
cloudFunctionDelete(newEvent).then((data: any) => {
112113
expect(data.metadata.creationTime).to.equal('2016-12-15T19:37:37.059Z');
113114
expect(data.metadata.lastSignInTime).to.equal('2017-01-01T00:00:00.000Z');
114115
}),
@@ -141,7 +142,7 @@ describe('Auth Functions', () => {
141142
});
142143

143144
it('will not interfere with fields that are in raw wire data', () => {
144-
const raw = {
145+
const raw: any = {
145146
uid: '123',
146147
email: 'email@gmail.com',
147148
emailVerified: true,

spec/providers/database.spec.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ describe('Database Functions', () => {
200200
});
201201

202202
describe('DataSnapshot', () => {
203-
let subject;
203+
let subject: any;
204204
const apps = new appsNamespace.Apps();
205205

206206
let populate = (data: any) => {
@@ -300,7 +300,7 @@ describe('Database Functions', () => {
300300
it('should iterate through child snapshots', () => {
301301
populate({ a: 'b', c: 'd' });
302302
let out = '';
303-
subject.forEach(snap => {
303+
subject.forEach((snap: any) => {
304304
out += snap.val();
305305
});
306306
expect(out).to.equal('bd');
@@ -309,7 +309,7 @@ describe('Database Functions', () => {
309309
it('should have correct key values for child snapshots', () => {
310310
populate({ a: 'b', c: 'd' });
311311
let out = '';
312-
subject.forEach(snap => {
312+
subject.forEach((snap: any) => {
313313
out += snap.key;
314314
});
315315
expect(out).to.equal('ac');
@@ -318,7 +318,7 @@ describe('Database Functions', () => {
318318
it('should not execute for leaf or null nodes', () => {
319319
populate(23);
320320
let count = 0;
321-
let counter = snap => count++;
321+
let counter = (snap: any) => count++;
322322

323323
expect(subject.forEach(counter)).to.equal(false);
324324
expect(count).to.eq(0);
@@ -327,7 +327,7 @@ describe('Database Functions', () => {
327327
it('should cancel further enumeration if callback returns true', () => {
328328
populate({ a: 'b', c: 'd', e: 'f', g: 'h' });
329329
let out = '';
330-
const ret = subject.forEach(snap => {
330+
const ret = subject.forEach((snap: any) => {
331331
if (snap.val() === 'f') {
332332
return true;
333333
}
@@ -340,7 +340,7 @@ describe('Database Functions', () => {
340340
it('should not cancel further enumeration if callback returns a truthy value', () => {
341341
populate({ a: 'b', c: 'd', e: 'f', g: 'h' });
342342
let out = '';
343-
const ret = subject.forEach(snap => {
343+
const ret = subject.forEach((snap: any) => {
344344
out += snap.val();
345345
return 1;
346346
});
@@ -351,7 +351,7 @@ describe('Database Functions', () => {
351351
it('should not cancel further enumeration if callback does not return', () => {
352352
populate({ a: 'b', c: 'd', e: 'f', g: 'h' });
353353
let out = '';
354-
const ret = subject.forEach(snap => {
354+
const ret = subject.forEach((snap: any) => {
355355
out += snap.val();
356356
});
357357
expect(out).to.equal('bdfh');

spec/providers/firestore.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import * as firestore from '../../src/providers/firestore';
2424
import { expect } from 'chai';
2525

2626
describe('Firestore Functions', () => {
27-
let constructValue = (fields) => {
27+
let constructValue = (fields: any) => {
2828
return {
2929
'fields': fields,
3030
'name': 'projects/pid/databases/(default)/documents/collection/123',
@@ -349,7 +349,7 @@ describe('Firestore Functions', () => {
349349
});
350350

351351
describe('Other DocumentSnapshot methods', () => {
352-
let snapshot;
352+
let snapshot: FirebaseFirestore.DocumentSnapshot;
353353

354354
before(() => {
355355
snapshot = firestore.snapshotConstructor({

spec/providers/https.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ function runHandler(handler: express.Handler, request: express.Request): Promise
8787
}
8888

8989
// Headers are only set by the cors handler.
90-
public setHeader(name, value: string) {
90+
public setHeader(name: string, value: string) {
9191
this.headers[name] = value;
9292
}
9393

@@ -201,7 +201,7 @@ export function generateIdToken(projectId: string): string {
201201
}
202202

203203
describe('callable.FunctionBuilder', () => {
204-
let app;
204+
let app: firebase.app.App;
205205

206206
before(() => {
207207
let credential = {

spec/providers/storage.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ describe('Storage Functions', () => {
8585
+ '/o/nestedfolder%2Fanotherfolder%2Fmyobject.file?generation=12345&alt=media',
8686
},
8787
};
88-
return cloudFunction(goodMediaLinkEvent).then(result => {
88+
return cloudFunction(goodMediaLinkEvent).then((result: any) => {
8989
expect(result).equals(goodMediaLinkEvent.data.mediaLink);
9090
});
9191
});
@@ -141,7 +141,7 @@ describe('Storage Functions', () => {
141141
+ '/o/nestedfolder%2Fanotherfolder%2Fmyobject.file?generation=12345&alt=media',
142142
},
143143
};
144-
return cloudFunction(goodMediaLinkEvent).then(result => {
144+
return cloudFunction(goodMediaLinkEvent).then((result: any) => {
145145
expect(result).equals(goodMediaLinkEvent.data.mediaLink);
146146
});
147147
});
@@ -197,7 +197,7 @@ describe('Storage Functions', () => {
197197
+ '/o/nestedfolder%2Fanotherfolder%2Fmyobject.file?generation=12345&alt=media',
198198
},
199199
};
200-
return cloudFunction(goodMediaLinkEvent).then(result => {
200+
return cloudFunction(goodMediaLinkEvent).then((result: any) => {
201201
expect(result).equals(goodMediaLinkEvent.data.mediaLink);
202202
});
203203
});
@@ -253,7 +253,7 @@ describe('Storage Functions', () => {
253253
+ '/o/nestedfolder%2Fanotherfolder%2Fmyobject.file?generation=12345&alt=media',
254254
},
255255
};
256-
return cloudFunction(goodMediaLinkEvent).then(result => {
256+
return cloudFunction(goodMediaLinkEvent).then((result: any) => {
257257
expect(result).equals(goodMediaLinkEvent.data.mediaLink);
258258
});
259259
});

spec/utils.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ describe ('utils', () => {
7272

7373
it('should return the merged value of two objects', () => {
7474
let from = {a: {b: 'foo', c: 23, d: 444}, d: {e: 42}};
75-
let to = {a: {b: 'bar', c: null}, d: null, e: {f: 'g'}};
75+
let to: any = {a: {b: 'bar', c: null}, d: null, e: {f: 'g'}};
7676
let result = {a: {b: 'bar', d: 444}, e: {f: 'g'}};
7777
expect(applyChange(from, to)).to.deep.equal(result);
7878
});

src/apps.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,15 @@ export namespace apps {
8383
}
8484

8585
retain() {
86-
let increment = n => {
86+
let increment = (n?: number) => {
8787
return (n || 0) + 1;
8888
};
8989
// Increment counter for admin because function might use event.data.ref
9090
_.update(this._refCounter, '__admin__', increment);
9191
}
9292

9393
release() {
94-
let decrement = n => {
94+
let decrement = (n: number) => {
9595
return n - 1;
9696
};
9797
return delay(garbageCollectionInterval).then(() => {

src/cloud-functions.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ export namespace Change {
117117
/** Factory method for creating a Change from a JSON and an optional customizer function to be
118118
* applied to both the `before` and the `after` fields.
119119
*/
120-
export function fromJSON<T>(json: ChangeJson, customizer: (any) => T = reinterpretCast): Change<T> {
120+
export function fromJSON<T>(json: ChangeJson, customizer: (x: any) => T = reinterpretCast): Change<T> {
121121
let before = _.assign({}, json.before);
122122
if (json.fieldMask) {
123123
before = applyFieldMask(before, json.after, json.fieldMask);
@@ -126,7 +126,7 @@ export namespace Change {
126126
}
127127

128128
/** @internal */
129-
export function applyFieldMask(sparseBefore, after, fieldMask) {
129+
export function applyFieldMask(sparseBefore: any, after: any, fieldMask: string) {
130130
let before = _.assign({}, after);
131131
let masks = fieldMask.split(',');
132132
_.forEach(masks, mask => {
@@ -216,7 +216,7 @@ export function makeCloudFunction<EventData>({
216216
before(event);
217217

218218
let dataOrChange = dataConstructor(event);
219-
let context;
219+
let context: any;
220220
if (isEvent(event)) { // new event format
221221
context = _.cloneDeep(event.context);
222222
} else { // legacy event format
@@ -276,7 +276,7 @@ function _makeParams(context: EventContext, triggerResourceGetter: () => string)
276276
}
277277
let triggerResource = triggerResourceGetter();
278278
let wildcards = triggerResource.match(WILDCARD_REGEX);
279-
let params = {};
279+
let params: { [option: string]: any } = {};
280280
if (wildcards) {
281281
let triggerResourceParts = _.split(triggerResource, '/');
282282
let eventResourceParts = _.split(context.resource.name, '/');

0 commit comments

Comments
 (0)