Skip to content

Commit 3426e2c

Browse files
authored
chore(build): Add strictNullCheck compatibility (angular#1030)
1 parent 6b82ff6 commit 3426e2c

13 files changed

+35
-33
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
"systemjs": "^0.19.16",
7676
"systemjs-builder": "^0.15.7",
7777
"traceur": "0.0.96",
78-
"typescript": "^2.2.2",
78+
"typescript": "^2.3.2",
7979
"zone.js": "^0.8.0"
8080
},
8181
"typings": "index.d.ts"

src/app/firebase.app.module.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ export function _firebaseAppFactory(config: FirebaseAppConfig, appName?: string)
2727
return firebase.app(e.name);
2828
}
2929

30-
return firebase.app(null);
30+
return firebase.app(null!);
3131
}
3232
}

src/auth/auth.spec.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ describe('AngularFireAuth', () => {
9191
// Check that the first value is null and second is the auth user
9292
const subs = afAuth.authState.subscribe(user => {
9393
if (count === 0) {
94-
expect(user).toBe(null);
94+
expect(user).toBe(null!);
9595
count = count + 1;
9696
mockAuthState.next(firebaseUser);
9797
} else {
@@ -100,7 +100,7 @@ describe('AngularFireAuth', () => {
100100
done();
101101
}
102102
}, done, done.fail);
103-
mockAuthState.next(null);
103+
mockAuthState.next(null!);
104104
});
105105

106106
it('should emit auth updates through idToken', (done: any) => {
@@ -109,7 +109,7 @@ describe('AngularFireAuth', () => {
109109
// Check that the first value is null and second is the auth user
110110
const subs = afAuth.idToken.subscribe(user => {
111111
if (count === 0) {
112-
expect(user).toBe(null);
112+
expect(user).toBe(null!);
113113
count = count + 1;
114114
mockAuthState.next(firebaseUser);
115115
} else {
@@ -118,7 +118,7 @@ describe('AngularFireAuth', () => {
118118
done();
119119
}
120120
}, done, done.fail);
121-
mockAuthState.next(null);
121+
mockAuthState.next(null!);
122122
});
123123

124124
});

src/auth/auth.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export class AngularFireAuth {
4242
export function FirebaseAuthStateObservable(app: FirebaseApp): Observable<firebase.User> {
4343
const authState = Observable.create((observer: Observer<firebase.User>) => {
4444
app.auth().onAuthStateChanged(
45-
(user?: firebase.User) => observer.next(user),
45+
(user?: firebase.User) => observer.next(user!),
4646
(error: firebase.auth.Error) => observer.error(error),
4747
() => observer.complete()
4848
);
@@ -58,10 +58,10 @@ export function FirebaseAuthStateObservable(app: FirebaseApp): Observable<fireba
5858
export function FirebaseIdTokenObservable(app: FirebaseApp): Observable<firebase.User> {
5959
const idToken = Observable.create((observer: Observer<firebase.User>) => {
6060
app.auth().onIdTokenChanged(
61-
(user?: firebase.User) => observer.next(user),
61+
(user?: firebase.User) => observer.next(user!),
6262
(error: firebase.auth.Error) => observer.error(error),
6363
() => observer.complete()
6464
)
6565
});
6666
return observeOn.call(idToken, new utils.ZoneScheduler(Zone.current));
67-
}
67+
}

src/database/firebase_list_factory.spec.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ describe('FirebaseListFactory', () => {
416416

417417
questions.$ref.ref.push({ number: 1 })
418418
.then(() => {
419-
let calls = [];
419+
let calls: string[] = [];
420420
questions.$ref.ref.once('child_added', (snap) => calls.push('child_added:' + snap.val().number));
421421
skipAndTake(questions).subscribe(
422422
(list) => {
@@ -611,13 +611,13 @@ describe('FirebaseListFactory', () => {
611611

612612
it('should move the child to the beginning if prevKey is null', () => {
613613
expect(
614-
onChildChanged([val1, val2, val3], val2, toKey, null)
614+
onChildChanged([val1, val2, val3], val2, toKey, null!)
615615
).toEqual([val2, val1, val3]);
616616
});
617617

618618
it('should not duplicate the first item if it is the one that changed', () => {
619619
expect(
620-
onChildChanged([val1, val2, val3], val1, toKey, null)
620+
onChildChanged([val1, val2, val3], val1, toKey, null!)
621621
).not.toEqual([val1, val1, val2, val3]);
622622
});
623623

src/database/firebase_list_factory.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { FirebaseListObservable } from './firebase_list_observable';
66
import { Observer } from 'rxjs/Observer';
77
import { observeOn } from 'rxjs/operator/observeOn';
88
import { observeQuery } from './query_observable';
9-
import { Query, FirebaseListFactoryOpts, DatabaseReference, DatabaseQuery } from '../interfaces';
9+
import { Query, FirebaseListFactoryOpts, DatabaseReference, DatabaseQuery, DatabaseSnapshot } from '../interfaces';
1010
import { switchMap } from 'rxjs/operator/switchMap';
1111
import { map } from 'rxjs/operator/map';
1212

@@ -115,10 +115,10 @@ function firebaseListObservable(ref: firebase.database.Reference | DatabaseQuery
115115
const listObs = new FirebaseListObservable(ref, (obs: Observer<any[]>) => {
116116

117117
// Keep track of callback handles for calling ref.off(event, handle)
118-
const handles = [];
118+
const handles: { event: string, handle: (a: DatabaseSnapshot, b?: string | null | undefined) => any }[] = [];
119119
let hasLoaded = false;
120-
let lastLoadedKey: string = null;
121-
let array = [];
120+
let lastLoadedKey: string = null!;
121+
let array: DatabaseSnapshot[] = [];
122122

123123
// The list children are always added to, removed from and changed within
124124
// the array using the child_added/removed/changed events. The value event
@@ -193,7 +193,7 @@ export function onChildAdded(arr:any[], child:any, toKey:(element:any)=>string,
193193
if (!arr.length) {
194194
return [child];
195195
}
196-
return arr.reduce((accumulator:firebase.database.DataSnapshot[], curr:firebase.database.DataSnapshot, i:number) => {
196+
return arr.reduce((accumulator: DatabaseSnapshot[], curr: DatabaseSnapshot, i:number) => {
197197
if (!prevKey && i===0) {
198198
accumulator.push(child);
199199
}

src/database/firebase_list_observable.spec.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ describe('FirebaseListObservable', () => {
5252

5353
describe('push', () => {
5454
it('should throw an exception if pushed when not subscribed', () => {
55-
O = new FirebaseListObservable(null, (observer:Observer<any>) => {});
55+
O = new FirebaseListObservable(null!, (observer:Observer<any>) => {});
5656

5757
expect(() => {
5858
O.push('foo');
@@ -76,7 +76,7 @@ describe('FirebaseListObservable', () => {
7676
let childAddedSpy = jasmine.createSpy('childAdded');
7777

7878
ref.on('child_added', childAddedSpy);
79-
O.remove(child.key)
79+
O.remove(child.key!)
8080
.then(() => (<any>ref).once('value'))
8181
.then((data:firebase.database.DataSnapshot) => {
8282
expect(childAddedSpy.calls.argsFor(0)[0].val()).toEqual(orphan);
@@ -158,7 +158,7 @@ describe('FirebaseListObservable', () => {
158158
let childChangedSpy = jasmine.createSpy('childChanged');
159159
const orphanChange = { changed: true }
160160
ref.on('child_changed', childChangedSpy);
161-
O.set(child.key, orphanChange)
161+
O.set(child.key!, orphanChange)
162162
.then(() => (<any>ref).once('value'))
163163
.then((data:firebase.database.DataSnapshot) => {
164164
expect(childChangedSpy.calls.argsFor(0)[0].val()).not.toEqual({
@@ -250,7 +250,7 @@ describe('FirebaseListObservable', () => {
250250
let childChangedSpy = jasmine.createSpy('childChanged');
251251
const orphanChange = { changed: true }
252252
ref.on('child_changed', childChangedSpy);
253-
O.update(child.key, orphanChange)
253+
O.update(child.key!, orphanChange)
254254
.then(() => (<any>ref).once('value'))
255255
.then((data:firebase.database.DataSnapshot) => {
256256
expect(childChangedSpy.calls.argsFor(0)[0].val()).toEqual({

src/database/firebase_list_observable.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,11 @@ export class FirebaseListObservable<T> extends Observable<T> {
6363
if (utils.isString(item)) {
6464
return cases.stringCase();
6565
} else if (utils.isFirebaseRef(item)) {
66-
return cases.firebaseCase();
66+
return cases.firebaseCase!();
6767
} else if (utils.isFirebaseDataSnapshot(item)) {
68-
return cases.snapshotCase();
68+
return cases.snapshotCase!();
6969
} else if (utils.isAFUnwrappedSnapshot(item)) {
70-
return cases.unwrappedSnapshotCase()
70+
return cases.unwrappedSnapshotCase!()
7171
}
7272
throw new Error(`Method requires a key, snapshot, reference, or unwrapped snapshot. Got: ${typeof item}`);
7373
}

src/database/firebase_object_observable.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ describe('FirebaseObjectObservable', () => {
4444

4545
describe('$ref', () => {
4646
it('should match the database path passed in the constructor', () => {
47-
expect(O.$ref.toString()).toEqual(ref.toString());
47+
expect(O.$ref!.toString()).toEqual(ref.toString());
4848
});
4949
});
5050

src/database/query_observable.spec.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ describe('observeQuery', () => {
3838
let completeSpy = jasmine.createSpy('complete');
3939
let query = { orderByChild: 'height', equalTo: 10 };
4040
let obs = observeQuery(query, false);
41-
obs.subscribe(nextSpy, null, completeSpy);
41+
obs.subscribe(nextSpy, () => {}, completeSpy);
4242
expect(nextSpy).toHaveBeenCalledWith({
4343
orderByChild: 'height',
4444
equalTo: 10
@@ -51,7 +51,7 @@ describe('observeQuery', () => {
5151
let completeSpy = jasmine.createSpy('complete');
5252
let query:any = null;
5353
let obs = observeQuery(query, false);
54-
obs.subscribe(nextSpy, null, completeSpy);
54+
obs.subscribe(nextSpy, () => {}, completeSpy);
5555
expect(nextSpy).toHaveBeenCalledWith(null);
5656
expect(completeSpy).toHaveBeenCalled();
5757
});
@@ -65,7 +65,7 @@ describe('observeQuery', () => {
6565
};
6666
let obs = observeQuery(query, false);
6767
let noOrderyQuery = { orderByKey: false };
68-
obs.subscribe(nextSpy, null, completeSpy);
68+
obs.subscribe(nextSpy, () => {}, completeSpy);
6969
query.orderByKey.next(true);
7070
expect(nextSpy).toHaveBeenCalledWith({ orderByKey: true});
7171
nextSpy.calls.reset();
@@ -82,11 +82,11 @@ describe('observeQuery', () => {
8282
orderByKey: new Subject<boolean>()
8383
};
8484
let obs = observeQuery(query, false);
85-
obs.subscribe(nextSpy, null, completeSpy);
85+
obs.subscribe(nextSpy, () => {}, completeSpy);
8686
query.orderByKey.next(true);
8787
expect(nextSpy).toHaveBeenCalledWith({ orderByKey: true });
8888
nextSpy.calls.reset();
89-
query.orderByKey.next(null);
89+
query.orderByKey.next(null!);
9090
expect(nextSpy).toHaveBeenCalledWith({});
9191
});
9292

src/database/query_observable.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { hasKey, isNil } from '../utils';
1111

1212
export function observeQuery(query: Query, audit: boolean = true): Observable<ScalarQuery> {
1313
if (isNil(query)) {
14-
return observableOf(null);
14+
return observableOf(null!);
1515
}
1616

1717
return Observable.create((observer: Observer<ScalarQuery>) => {
@@ -93,7 +93,7 @@ export function getOrderObservables(query: Query): Observable<OrderBySelection>
9393
return merge.apply(observables[0], observables.slice(1));
9494
} else {
9595
return new Observable<OrderBySelection>(subscriber => {
96-
subscriber.next(null);
96+
subscriber.next(null!);
9797
});
9898
}
9999
}
@@ -111,7 +111,7 @@ export function getLimitToObservables(query: Query): Observable<LimitToSelection
111111
return mergedObs;
112112
} else {
113113
return new Observable<LimitToSelection>(subscriber => {
114-
subscriber.next(null);
114+
subscriber.next(null!);
115115
});
116116
}
117117
}

tsconfig.json

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"inlineSources": true,
1212
"declaration": true,
1313
"removeComments": true,
14+
"strictNullChecks": true,
1415
"lib": [
1516
"es2015",
1617
"dom"

tsconfig.publish.es6.json

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"inlineSources": true,
1212
"declaration": true,
1313
"removeComments": true,
14+
"strictNullChecks": true,
1415
"lib": [
1516
"es2015",
1617
"dom"

0 commit comments

Comments
 (0)