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

Commit 915042d

Browse files
JiaLiPassionmhevery
authored andcommitted
fix(tsc): tsconfig.json strict:true
1 parent 1ba8519 commit 915042d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+549
-519
lines changed

Diff for: lib/browser/browser.ts

+8-14
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ Zone.__load_patch('XHR', (global: any, Zone: ZoneType) => {
154154
if (!storedTask) {
155155
target[XHR_TASK] = task;
156156
}
157-
sendNative.apply(target, data.args);
157+
sendNative!.apply(target, data.args);
158158
(XMLHttpRequest as any)[XHR_SCHEDULED] = true;
159159
return task;
160160
}
@@ -166,31 +166,25 @@ Zone.__load_patch('XHR', (global: any, Zone: ZoneType) => {
166166
// Note - ideally, we would call data.target.removeEventListener here, but it's too late
167167
// to prevent it from firing. So instead, we store info for the event listener.
168168
data.aborted = true;
169-
return abortNative.apply(data.target, data.args);
169+
return abortNative!.apply(data.target, data.args);
170170
}
171171

172-
const openNative: Function =
172+
const openNative =
173173
patchMethod(XMLHttpRequestPrototype, 'open', () => function(self: any, args: any[]) {
174174
self[XHR_SYNC] = args[2] == false;
175175
self[XHR_URL] = args[1];
176-
return openNative.apply(self, args);
176+
return openNative!.apply(self, args);
177177
});
178178

179179
const XMLHTTPREQUEST_SOURCE = 'XMLHttpRequest.send';
180-
const sendNative: Function =
180+
const sendNative =
181181
patchMethod(XMLHttpRequestPrototype, 'send', () => function(self: any, args: any[]) {
182182
if (self[XHR_SYNC]) {
183183
// if the XHR is sync there is no task to schedule, just execute the code.
184-
return sendNative.apply(self, args);
184+
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
}

Diff for: 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) {

Diff for: 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
}

Diff for: 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();

Diff for: 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) {

Diff for: lib/common/promise.ts

+18-12
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ Zone.__load_patch('ZoneAwarePromise', (global: any, Zone: ZoneType, api: _ZonePr
4646
api.microtaskDrainDone = () => {
4747
while (_uncaughtPromiseErrors.length) {
4848
while (_uncaughtPromiseErrors.length) {
49-
const uncaughtPromiseError: UncaughtPromiseError = _uncaughtPromiseErrors.shift();
49+
const uncaughtPromiseError: UncaughtPromiseError = _uncaughtPromiseErrors.shift()!;
5050
try {
5151
uncaughtPromiseError.zone.runGuarded(() => {
5252
throw uncaughtPromiseError;
@@ -164,7 +164,7 @@ Zone.__load_patch('ZoneAwarePromise', (global: any, Zone: ZoneType, api: _ZonePr
164164
(promise as any)[symbolValue] = value;
165165

166166
if ((promise as any)[symbolFinally] === symbolFinally) {
167-
// the promise is generated by Promise.prototype.finally
167+
// the promise is generated by Promise.prototype.finally
168168
if (state === RESOLVED) {
169169
// the state is resolved, should ignore the value
170170
// and use parent promise value
@@ -202,7 +202,7 @@ Zone.__load_patch('ZoneAwarePromise', (global: any, Zone: ZoneType, api: _ZonePr
202202
error.rejection = value;
203203
error.promise = promise;
204204
error.zone = Zone.current;
205-
error.task = Zone.currentTask;
205+
error.task = Zone.currentTask!;
206206
_uncaughtPromiseErrors.push(error);
207207
api.scheduleMicroTask(); // to make sure that it is running
208208
}
@@ -239,7 +239,8 @@ Zone.__load_patch('ZoneAwarePromise', (global: any, Zone: ZoneType, api: _ZonePr
239239

240240
function scheduleResolveOrReject<R, U1, U2>(
241241
promise: ZoneAwarePromise<any>, zone: AmbientZone, chainPromise: ZoneAwarePromise<any>,
242-
onFulfilled?: (value: R) => U1, onRejected?: (error: any) => U2): void {
242+
onFulfilled?: ((value: R) => U1) | null | undefined,
243+
onRejected?: ((error: any) => U2) | null | undefined): void {
243244
clearRejectedNoCatch(promise);
244245
const promiseState = (promise as any)[symbolState];
245246
const delegate = promiseState ?
@@ -248,14 +249,19 @@ Zone.__load_patch('ZoneAwarePromise', (global: any, Zone: ZoneType, api: _ZonePr
248249
zone.scheduleMicroTask(source, () => {
249250
try {
250251
const parentPromiseValue = (promise as any)[symbolValue];
251-
const isFinallyPromise = chainPromise && symbolFinally === (chainPromise as any)[symbolFinally];
252+
const isFinallyPromise =
253+
chainPromise && symbolFinally === (chainPromise as any)[symbolFinally];
252254
if (isFinallyPromise) {
253255
// if the promise is generated from finally call, keep parent promise's state and value
254256
(chainPromise as any)[symbolParentPromiseValue] = parentPromiseValue;
255257
(chainPromise as any)[symbolParentPromiseState] = promiseState;
256258
}
257259
// should not pass value to finally callback
258-
const value = zone.run(delegate, undefined, isFinallyPromise && delegate !== forwardRejection && delegate !== forwardResolution ? [] : [parentPromiseValue]);
260+
const value = zone.run(
261+
delegate, undefined,
262+
isFinallyPromise && delegate !== forwardRejection && delegate !== forwardResolution ?
263+
[] :
264+
[parentPromiseValue]);
259265
resolvePromise(chainPromise, true, value);
260266
} catch (error) {
261267
// if error occurs, should always return this error
@@ -272,11 +278,11 @@ Zone.__load_patch('ZoneAwarePromise', (global: any, Zone: ZoneType, api: _ZonePr
272278
}
273279

274280
static resolve<R>(value: R): Promise<R> {
275-
return resolvePromise(<ZoneAwarePromise<R>>new this(null), RESOLVED, value);
281+
return resolvePromise(<ZoneAwarePromise<R>>new this(null as any), RESOLVED, value);
276282
}
277283

278284
static reject<U>(error: U): Promise<U> {
279-
return resolvePromise(<ZoneAwarePromise<U>>new this(null), REJECTED, error);
285+
return resolvePromise(<ZoneAwarePromise<U>>new this(null as any), REJECTED, error);
280286
}
281287

282288
static race<R>(values: PromiseLike<any>[]): Promise<R> {
@@ -323,10 +329,10 @@ Zone.__load_patch('ZoneAwarePromise', (global: any, Zone: ZoneType, api: _ZonePr
323329
resolve(resolvedValues);
324330
}
325331
})(count),
326-
reject);
332+
reject!);
327333
count++;
328334
}
329-
if (!count) resolve(resolvedValues);
335+
if (!count) resolve!(resolvedValues);
330336
return promise;
331337
}
332338

@@ -351,7 +357,7 @@ Zone.__load_patch('ZoneAwarePromise', (global: any, Zone: ZoneType, api: _ZonePr
351357
onRejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>)|undefined|
352358
null): Promise<TResult1|TResult2> {
353359
const chainPromise: Promise<TResult1|TResult2> =
354-
new (this.constructor as typeof ZoneAwarePromise)(null);
360+
new (this.constructor as typeof ZoneAwarePromise)(null as any);
355361
const zone = Zone.current;
356362
if ((this as any)[symbolState] == UNRESOLVED) {
357363
(<any[]>(this as any)[symbolValue]).push(zone, chainPromise, onFulfilled, onRejected);
@@ -368,7 +374,7 @@ Zone.__load_patch('ZoneAwarePromise', (global: any, Zone: ZoneType, api: _ZonePr
368374

369375
finally<U>(onFinally?: () => U | PromiseLike<U>): Promise<R> {
370376
const chainPromise: Promise<R|never> =
371-
new (this.constructor as typeof ZoneAwarePromise)(null);
377+
new (this.constructor as typeof ZoneAwarePromise)(null as any);
372378
(chainPromise as any)[symbolFinally] = symbolFinally;
373379
const zone = Zone.current;
374380
if ((this as any)[symbolState] == UNRESOLVED) {

Diff for: 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) {

Diff for: 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

Diff for: 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
});

Diff for: 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)