Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.

Commit 945eb1a

Browse files
committed
WIP(tsc): tsconfig.json strict:true
1 parent eefe983 commit 945eb1a

19 files changed

+283
-305
lines changed

lib/browser/browser.ts

+2-8
Original file line numberDiff line numberDiff line change
@@ -183,14 +183,8 @@ Zone.__load_patch('XHR', (global: any, Zone: ZoneType) => {
183183
// if the XHR is sync there is no task to schedule, just execute the code.
184184
return sendNative.apply(self, args);
185185
} else {
186-
const options: XHROptions = {
187-
target: self,
188-
url: self[XHR_URL],
189-
isPeriodic: false,
190-
delay: null,
191-
args: args,
192-
aborted: false
193-
};
186+
const options: XHROptions =
187+
{target: self, url: self[XHR_URL], isPeriodic: false, args: args, aborted: false};
194188
return scheduleMacroTaskWithCurrentZone(
195189
XMLHTTPREQUEST_SOURCE, placeholderCallback, options, scheduleTask, clearTask);
196190
}

lib/browser/define-property.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export function propertyPatch() {
4848

4949
Object.getOwnPropertyDescriptor = function(obj, prop) {
5050
const desc = _getOwnPropertyDescriptor(obj, prop);
51-
if (isUnconfigurable(obj, prop)) {
51+
if (desc && isUnconfigurable(obj, prop)) {
5252
desc.configurable = false;
5353
}
5454
return desc;
@@ -97,7 +97,7 @@ function _tryDefineProperty(obj: any, prop: string, desc: any, originalConfigura
9797
try {
9898
return _defineProperty(obj, prop, desc);
9999
} catch (error) {
100-
let descJson: string = null;
100+
let descJson: string|null = null;
101101
try {
102102
descJson = JSON.stringify(desc);
103103
} catch (error) {

lib/browser/property-descriptor.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ function canPatchViaPropertyDescriptor() {
384384
const detectFunc = () => {};
385385
req.onreadystatechange = detectFunc;
386386
const result = (req as any)[SYMBOL_FAKE_ONREADYSTATECHANGE] === detectFunc;
387-
req.onreadystatechange = null;
387+
req.onreadystatechange = null as any;
388388
return result;
389389
}
390390
}

lib/common/error-rewrite.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ Zone.__load_patch('Error', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
6363
// Process the stack trace and rewrite the frames.
6464
if ((ZoneAwareError as any)[stackRewrite] && originalStack) {
6565
let frames: string[] = originalStack.split('\n');
66-
let zoneFrame = api.currentZoneFrame();
66+
let zoneFrame: _ZoneFrame|null = api.currentZoneFrame();
6767
let i = 0;
6868
// Find the first frame
6969
while (!(frames[i] === zoneAwareFrame1 || frames[i] === zoneAwareFrame2) &&
@@ -295,20 +295,20 @@ Zone.__load_patch('Error', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
295295
() => {
296296
throw new (ZoneAwareError as any)(ZoneAwareError, NativeError);
297297
},
298-
null,
298+
undefined,
299299
(t: Task) => {
300300
(t as any)._transitionTo = fakeTransitionTo;
301301
t.invoke();
302302
});
303303
},
304-
null,
304+
undefined,
305305
(t) => {
306306
(t as any)._transitionTo = fakeTransitionTo;
307307
t.invoke();
308308
},
309309
() => {});
310310
},
311-
null,
311+
undefined,
312312
(t) => {
313313
(t as any)._transitionTo = fakeTransitionTo;
314314
t.invoke();

lib/common/events.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ export function patchEventTarget(
398398
taskData.eventName = eventName;
399399
taskData.isExisting = isExisting;
400400

401-
const data = useGlobalCallback ? OPTIMIZED_ZONE_EVENT_TASK_DATA : null;
401+
const data = useGlobalCallback ? OPTIMIZED_ZONE_EVENT_TASK_DATA : undefined;
402402

403403
// keep taskData into data to allow onScheduleEventTask to access the task information
404404
if (data) {

lib/common/promise.ts

+19-13
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Zone.__load_patch('ZoneAwarePromise', (global: any, Zone: ZoneType, api: _ZonePr
2424

2525
interface UncaughtPromiseError extends Error {
2626
zone: AmbientZone;
27-
task: Task;
27+
task?: Task;
2828
promise: ZoneAwarePromise<any>;
2929
rejection: any;
3030
}
@@ -53,7 +53,7 @@ Zone.__load_patch('ZoneAwarePromise', (global: any, Zone: ZoneType, api: _ZonePr
5353
api.microtaskDrainDone = () => {
5454
while (_uncaughtPromiseErrors.length) {
5555
while (_uncaughtPromiseErrors.length) {
56-
const uncaughtPromiseError: UncaughtPromiseError = _uncaughtPromiseErrors.shift();
56+
const uncaughtPromiseError: UncaughtPromiseError = _uncaughtPromiseErrors.shift()!;
5757
try {
5858
uncaughtPromiseError.zone.runGuarded(() => {
5959
throw uncaughtPromiseError;
@@ -171,7 +171,7 @@ Zone.__load_patch('ZoneAwarePromise', (global: any, Zone: ZoneType, api: _ZonePr
171171
(promise as any)[symbolValue] = value;
172172

173173
if ((promise as any)[symbolFinally] === symbolFinally) {
174-
// the promise is generated by Promise.prototype.finally
174+
// the promise is generated by Promise.prototype.finally
175175
if (state === RESOLVED) {
176176
// the state is resolved, should ignore the value
177177
// and use parent promise value
@@ -209,7 +209,7 @@ Zone.__load_patch('ZoneAwarePromise', (global: any, Zone: ZoneType, api: _ZonePr
209209
error.rejection = value;
210210
error.promise = promise;
211211
error.zone = Zone.current;
212-
error.task = Zone.currentTask;
212+
error.task = Zone.currentTask!;
213213
_uncaughtPromiseErrors.push(error);
214214
api.scheduleMicroTask(); // to make sure that it is running
215215
}
@@ -246,7 +246,8 @@ Zone.__load_patch('ZoneAwarePromise', (global: any, Zone: ZoneType, api: _ZonePr
246246

247247
function scheduleResolveOrReject<R, U1, U2>(
248248
promise: ZoneAwarePromise<any>, zone: AmbientZone, chainPromise: ZoneAwarePromise<any>,
249-
onFulfilled?: (value: R) => U1, onRejected?: (error: any) => U2): void {
249+
onFulfilled?: ((value: R) => U1) | null | undefined,
250+
onRejected?: ((error: any) => U2) | null | undefined): void {
250251
clearRejectedNoCatch(promise);
251252
const promiseState = (promise as any)[symbolState];
252253
const delegate = promiseState ?
@@ -255,14 +256,19 @@ Zone.__load_patch('ZoneAwarePromise', (global: any, Zone: ZoneType, api: _ZonePr
255256
zone.scheduleMicroTask(source, () => {
256257
try {
257258
const parentPromiseValue = (promise as any)[symbolValue];
258-
const isFinallyPromise = chainPromise && symbolFinally === (chainPromise as any)[symbolFinally];
259+
const isFinallyPromise =
260+
chainPromise && symbolFinally === (chainPromise as any)[symbolFinally];
259261
if (isFinallyPromise) {
260262
// if the promise is generated from finally call, keep parent promise's state and value
261263
(chainPromise as any)[symbolParentPromiseValue] = parentPromiseValue;
262264
(chainPromise as any)[symbolParentPromiseState] = promiseState;
263265
}
264266
// should not pass value to finally callback
265-
const value = zone.run(delegate, undefined, isFinallyPromise && delegate !== forwardRejection && delegate !== forwardResolution ? [] : [parentPromiseValue]);
267+
const value = zone.run(
268+
delegate, undefined,
269+
isFinallyPromise && delegate !== forwardRejection && delegate !== forwardResolution ?
270+
[] :
271+
[parentPromiseValue]);
266272
resolvePromise(chainPromise, true, value);
267273
} catch (error) {
268274
// if error occurs, should always return this error
@@ -279,11 +285,11 @@ Zone.__load_patch('ZoneAwarePromise', (global: any, Zone: ZoneType, api: _ZonePr
279285
}
280286

281287
static resolve<R>(value: R): Promise<R> {
282-
return resolvePromise(<ZoneAwarePromise<R>>new this(null), RESOLVED, value);
288+
return resolvePromise(<ZoneAwarePromise<R>>new this(null as any), RESOLVED, value);
283289
}
284290

285291
static reject<U>(error: U): Promise<U> {
286-
return resolvePromise(<ZoneAwarePromise<U>>new this(null), REJECTED, error);
292+
return resolvePromise(<ZoneAwarePromise<U>>new this(null as any), REJECTED, error);
287293
}
288294

289295
static race<R>(values: PromiseLike<any>[]): Promise<R> {
@@ -330,10 +336,10 @@ Zone.__load_patch('ZoneAwarePromise', (global: any, Zone: ZoneType, api: _ZonePr
330336
resolve(resolvedValues);
331337
}
332338
})(count),
333-
reject);
339+
reject!);
334340
count++;
335341
}
336-
if (!count) resolve(resolvedValues);
342+
if (!count) resolve!(resolvedValues);
337343
return promise;
338344
}
339345

@@ -358,7 +364,7 @@ Zone.__load_patch('ZoneAwarePromise', (global: any, Zone: ZoneType, api: _ZonePr
358364
onRejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>)|undefined|
359365
null): Promise<TResult1|TResult2> {
360366
const chainPromise: Promise<TResult1|TResult2> =
361-
new (this.constructor as typeof ZoneAwarePromise)(null);
367+
new (this.constructor as typeof ZoneAwarePromise)(null as any);
362368
const zone = Zone.current;
363369
if ((this as any)[symbolState] == UNRESOLVED) {
364370
(<any[]>(this as any)[symbolValue]).push(zone, chainPromise, onFulfilled, onRejected);
@@ -375,7 +381,7 @@ Zone.__load_patch('ZoneAwarePromise', (global: any, Zone: ZoneType, api: _ZonePr
375381

376382
finally<U>(onFinally?: () => U | PromiseLike<U>): Promise<R> {
377383
const chainPromise: Promise<R|never> =
378-
new (this.constructor as typeof ZoneAwarePromise)(null);
384+
new (this.constructor as typeof ZoneAwarePromise)(null as any);
379385
(chainPromise as any)[symbolFinally] = symbolFinally;
380386
const zone = Zone.current;
381387
if ((this as any)[symbolState] == UNRESOLVED) {

lib/common/timers.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ import {patchMethod, scheduleMacroTaskWithCurrentZone, zoneSymbol} from './utils
1515
const taskSymbol = zoneSymbol('zoneTask');
1616

1717
interface TimerOptions extends TaskData {
18-
handleId: number;
18+
handleId?: number;
1919
args: any[];
2020
}
2121

2222
export function patchTimer(window: any, setName: string, cancelName: string, nameSuffix: string) {
23-
let setNative: Function = null;
24-
let clearNative: Function = null;
23+
let setNative: Function|null = null;
24+
let clearNative: Function|null = null;
2525
setName += nameSuffix;
2626
cancelName += nameSuffix;
2727

@@ -50,21 +50,21 @@ export function patchTimer(window: any, setName: string, cancelName: string, nam
5050
}
5151
}
5252
data.args[0] = timer;
53-
data.handleId = setNative.apply(window, data.args);
53+
data.handleId = setNative!.apply(window, data.args);
5454
return task;
5555
}
5656

5757
function clearTask(task: Task) {
58-
return clearNative((<TimerOptions>task.data).handleId);
58+
return clearNative!((<TimerOptions>task.data).handleId);
5959
}
6060

6161
setNative =
6262
patchMethod(window, setName, (delegate: Function) => function(self: any, args: any[]) {
6363
if (typeof args[0] === 'function') {
6464
const options: TimerOptions = {
65-
handleId: null,
6665
isPeriodic: nameSuffix === 'Interval',
67-
delay: (nameSuffix === 'Timeout' || nameSuffix === 'Interval') ? args[1] || 0 : null,
66+
delay: (nameSuffix === 'Timeout' || nameSuffix === 'Interval') ? args[1] || 0 :
67+
undefined,
6868
args: args
6969
};
7070
const task =
@@ -118,7 +118,7 @@ export function patchTimer(window: any, setName: string, cancelName: string, nam
118118
}
119119
if (task && typeof task.type === 'string') {
120120
if (task.state !== 'notScheduled' &&
121-
(task.cancelFn && task.data.isPeriodic || task.runCount === 0)) {
121+
(task.cancelFn && task.data!.isPeriodic || task.runCount === 0)) {
122122
if (typeof id === 'number') {
123123
delete tasksByHandleId[id];
124124
} else if (id) {

lib/common/utils.ts

+12-13
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ export function wrapWithCurrentZone<T extends Function>(callback: T, source: str
4343
}
4444

4545
export function scheduleMacroTaskWithCurrentZone(
46-
source: string, callback: Function, data: TaskData, customSchedule: (task: Task) => void,
47-
customCancel: (task: Task) => void): MacroTask {
46+
source: string, callback: Function, data?: TaskData, customSchedule?: (task: Task) => void,
47+
customCancel?: (task: Task) => void): MacroTask {
4848
return Zone.current.scheduleMacroTask(source, callback, data, customSchedule, customCancel);
4949
}
5050

@@ -229,7 +229,7 @@ export function patchProperty(obj: any, prop: string, prototype?: any) {
229229
// so we should use original native get to retrieve the handler
230230
let value = originalDescGet && originalDescGet.call(this);
231231
if (value) {
232-
desc.set.call(this, value);
232+
desc!.set!.call(this, value);
233233
if (typeof target[REMOVE_ATTRIBUTE] === 'function') {
234234
target.removeAttribute(prop);
235235
}
@@ -242,7 +242,7 @@ export function patchProperty(obj: any, prop: string, prototype?: any) {
242242
ObjectDefineProperty(obj, prop, desc);
243243
}
244244

245-
export function patchOnProperties(obj: any, properties: string[], prototype?: any) {
245+
export function patchOnProperties(obj: any, properties: string[]|null, prototype?: any) {
246246
if (properties) {
247247
for (let i = 0; i < properties.length; i++) {
248248
patchProperty(obj, 'on' + properties[i], prototype);
@@ -337,7 +337,7 @@ export function patchClass(className: string) {
337337
export function patchMethod(
338338
target: any, name: string,
339339
patchFn: (delegate: Function, delegateName: string, name: string) => (self: any, args: any[]) =>
340-
any): Function {
340+
any): Function|null {
341341
let proto = target;
342342
while (proto && !proto.hasOwnProperty(name)) {
343343
proto = ObjectGetPrototypeOf(proto);
@@ -348,14 +348,14 @@ export function patchMethod(
348348
}
349349

350350
const delegateName = zoneSymbol(name);
351-
let delegate: Function;
351+
let delegate: Function|null = null;
352352
if (proto && !(delegate = proto[delegateName])) {
353353
delegate = proto[delegateName] = proto[name];
354354
// check whether proto[name] is writable
355355
// some property is readonly in safari, such as HtmlCanvasElement.prototype.toBlob
356356
const desc = proto && ObjectGetOwnPropertyDescriptor(proto, name);
357357
if (isPropertyWritable(desc)) {
358-
const patchDelegate = patchFn(delegate, delegateName, name);
358+
const patchDelegate = patchFn(delegate!, delegateName, name);
359359
proto[name] = function() {
360360
return patchDelegate(this, arguments as any);
361361
};
@@ -375,22 +375,21 @@ export interface MacroTaskMeta extends TaskData {
375375
// TODO: @JiaLiPassion, support cancel task later if necessary
376376
export function patchMacroTask(
377377
obj: any, funcName: string, metaCreator: (self: any, args: any[]) => MacroTaskMeta) {
378-
let setNative: Function = null;
378+
let setNative: Function|null = null;
379379

380380
function scheduleTask(task: Task) {
381381
const data = <MacroTaskMeta>task.data;
382382
data.args[data.cbIdx] = function() {
383383
task.invoke.apply(this, arguments);
384384
};
385-
setNative.apply(data.target, data.args);
385+
setNative!.apply(data.target, data.args);
386386
return task;
387387
}
388388

389389
setNative = patchMethod(obj, funcName, (delegate: Function) => function(self: any, args: any[]) {
390390
const meta = metaCreator(self, args);
391391
if (meta.cbIdx >= 0 && typeof args[meta.cbIdx] === 'function') {
392-
return scheduleMacroTaskWithCurrentZone(
393-
meta.name, args[meta.cbIdx], meta, scheduleTask, null);
392+
return scheduleMacroTaskWithCurrentZone(meta.name, args[meta.cbIdx], meta, scheduleTask);
394393
} else {
395394
// cause an error by calling it directly.
396395
return delegate.apply(self, args);
@@ -407,14 +406,14 @@ export interface MicroTaskMeta extends TaskData {
407406

408407
export function patchMicroTask(
409408
obj: any, funcName: string, metaCreator: (self: any, args: any[]) => MicroTaskMeta) {
410-
let setNative: Function = null;
409+
let setNative: Function|null = null;
411410

412411
function scheduleTask(task: Task) {
413412
const data = <MacroTaskMeta>task.data;
414413
data.args[data.cbIdx] = function() {
415414
task.invoke.apply(this, arguments);
416415
};
417-
setNative.apply(data.target, data.args);
416+
setNative!.apply(data.target, data.args);
418417
return task;
419418
}
420419

lib/extra/cordova.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ Zone.__load_patch('cordova', (global: any, Zone: ZoneType, api: _ZonePrivate) =>
1010
const SUCCESS_SOURCE = 'cordova.exec.success';
1111
const ERROR_SOURCE = 'cordova.exec.error';
1212
const FUNCTION = 'function';
13-
const nativeExec: Function =
13+
const nativeExec: Function|null =
1414
api.patchMethod(global.cordova, 'exec', () => function(self: any, args: any[]) {
1515
if (args.length > 0 && typeof args[0] === FUNCTION) {
1616
args[0] = Zone.current.wrap(args[0], SUCCESS_SOURCE);
1717
}
1818
if (args.length > 1 && typeof args[1] === FUNCTION) {
1919
args[1] = Zone.current.wrap(args[1], ERROR_SOURCE);
2020
}
21-
return nativeExec.apply(self, args);
21+
return nativeExec!.apply(self, args);
2222
});
2323
}
2424
});

lib/extra/electron.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88
Zone.__load_patch('electron', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
9-
function patchArguments(target: any, name: string, source: string): Function {
9+
function patchArguments(target: any, name: string, source: string): Function|null {
1010
return api.patchMethod(target, name, (delegate: Function) => (self: any, args: any[]) => {
1111
return delegate && delegate.apply(self, api.bindArguments(args, source));
1212
});

0 commit comments

Comments
 (0)