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

47 files changed

Lines changed: 549 additions & 519 deletions

Some content is hidden

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

‎lib/browser/browser.ts‎

Lines changed: 8 additions & 14 deletions
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
(XMLHttpRequestasany)[XHR_SCHEDULED]=true;
159159
returntask;
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-
returnabortNative.apply(data.target,data.args);
169+
returnabortNative!.apply(data.target,data.args);
170170
}
171171

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

179179
constXMLHTTPREQUEST_SOURCE='XMLHttpRequest.send';
180-
constsendNative: Function=
180+
constsendNative=
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-
returnsendNative.apply(self,args);
184+
returnsendNative!.apply(self,args);
185185
}else{
186-
constoptions: XHROptions={
187-
target: self,
188-
url: self[XHR_URL],
189-
isPeriodic: false,
190-
delay: null,
191-
args: args,
192-
aborted: false
193-
};
186+
constoptions: XHROptions=
187+
{target: self,url: self[XHR_URL],isPeriodic: false,args: args,aborted: false};
194188
returnscheduleMacroTaskWithCurrentZone(
195189
XMLHTTPREQUEST_SOURCE,placeholderCallback,options,scheduleTask,clearTask);
196190
}

‎lib/browser/define-property.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export function propertyPatch() {
4848

4949
Object.getOwnPropertyDescriptor=function(obj,prop){
5050
constdesc=_getOwnPropertyDescriptor(obj,prop);
51-
if(isUnconfigurable(obj,prop)){
51+
if(desc&&isUnconfigurable(obj,prop)){
5252
desc.configurable=false;
5353
}
5454
returndesc;
@@ -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-
letdescJson: string=null;
100+
letdescJson: string|null=null;
101101
try{
102102
descJson=JSON.stringify(desc);
103103
}catch(error){

‎lib/browser/property-descriptor.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ function canPatchViaPropertyDescriptor() {
384384
constdetectFunc=()=>{};
385385
req.onreadystatechange=detectFunc;
386386
constresult=(reqasany)[SYMBOL_FAKE_ONREADYSTATECHANGE]===detectFunc;
387-
req.onreadystatechange=null;
387+
req.onreadystatechange=nullasany;
388388
returnresult;
389389
}
390390
}

‎lib/common/error-rewrite.ts‎

Lines changed: 4 additions & 4 deletions
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((ZoneAwareErrorasany)[stackRewrite]&&originalStack){
6565
letframes: string[]=originalStack.split('\n');
66-
letzoneFrame=api.currentZoneFrame();
66+
letzoneFrame: _ZoneFrame|null=api.currentZoneFrame();
6767
leti=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
thrownew(ZoneAwareErrorasany)(ZoneAwareError,NativeError);
297297
},
298-
null,
298+
undefined,
299299
(t: Task)=>{
300300
(tasany)._transitionTo=fakeTransitionTo;
301301
t.invoke();
302302
});
303303
},
304-
null,
304+
undefined,
305305
(t)=>{
306306
(tasany)._transitionTo=fakeTransitionTo;
307307
t.invoke();
308308
},
309309
()=>{});
310310
},
311-
null,
311+
undefined,
312312
(t)=>{
313313
(tasany)._transitionTo=fakeTransitionTo;
314314
t.invoke();

‎lib/common/events.ts‎

Lines changed: 1 addition & 1 deletion
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-
constdata=useGlobalCallback ? OPTIMIZED_ZONE_EVENT_TASK_DATA : null;
401+
constdata=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‎

Lines changed: 18 additions & 12 deletions
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-
constuncaughtPromiseError: UncaughtPromiseError=_uncaughtPromiseErrors.shift();
49+
constuncaughtPromiseError: UncaughtPromiseError=_uncaughtPromiseErrors.shift()!;
5050
try{
5151
uncaughtPromiseError.zone.runGuarded(()=>{
5252
throwuncaughtPromiseError;
@@ -164,7 +164,7 @@ Zone.__load_patch('ZoneAwarePromise', (global: any, Zone: ZoneType, api: _ZonePr
164164
(promiseasany)[symbolValue]=value;
165165

166166
if((promiseasany)[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
functionscheduleResolveOrReject<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
constpromiseState=(promiseasany)[symbolState];
245246
constdelegate=promiseState ?
@@ -248,14 +249,19 @@ Zone.__load_patch('ZoneAwarePromise', (global: any, Zone: ZoneType, api: _ZonePr
248249
zone.scheduleMicroTask(source,()=>{
249250
try{
250251
constparentPromiseValue=(promiseasany)[symbolValue];
251-
constisFinallyPromise=chainPromise&&symbolFinally===(chainPromiseasany)[symbolFinally];
252+
constisFinallyPromise=
253+
chainPromise&&symbolFinally===(chainPromiseasany)[symbolFinally];
252254
if(isFinallyPromise){
253255
// if the promise is generated from finally call, keep parent promise's state and value
254256
(chainPromiseasany)[symbolParentPromiseValue]=parentPromiseValue;
255257
(chainPromiseasany)[symbolParentPromiseState]=promiseState;
256258
}
257259
// should not pass value to finally callback
258-
constvalue=zone.run(delegate,undefined,isFinallyPromise&&delegate!==forwardRejection&&delegate!==forwardResolution ? [] : [parentPromiseValue]);
260+
constvalue=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
staticresolve<R>(value: R): Promise<R>{
275-
returnresolvePromise(<ZoneAwarePromise<R>>newthis(null),RESOLVED,value);
281+
returnresolvePromise(<ZoneAwarePromise<R>>newthis(nullasany),RESOLVED,value);
276282
}
277283

278284
staticreject<U>(error: U): Promise<U>{
279-
returnresolvePromise(<ZoneAwarePromise<U>>newthis(null),REJECTED,error);
285+
returnresolvePromise(<ZoneAwarePromise<U>>newthis(nullasany),REJECTED,error);
280286
}
281287

282288
staticrace<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
returnpromise;
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
constchainPromise: Promise<TResult1|TResult2>=
354-
new(this.constructorastypeofZoneAwarePromise)(null);
360+
new(this.constructorastypeofZoneAwarePromise)(nullasany);
355361
constzone=Zone.current;
356362
if((thisasany)[symbolState]==UNRESOLVED){
357363
(<any[]>(thisasany)[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
constchainPromise: Promise<R|never>=
371-
new(this.constructorastypeofZoneAwarePromise)(null);
377+
new(this.constructorastypeofZoneAwarePromise)(nullasany);
372378
(chainPromiseasany)[symbolFinally]=symbolFinally;
373379
constzone=Zone.current;
374380
if((thisasany)[symbolState]==UNRESOLVED){

‎lib/common/timers.ts‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ import {patchMethod, scheduleMacroTaskWithCurrentZone, zoneSymbol} from './utils
1515
consttaskSymbol=zoneSymbol('zoneTask');
1616

1717
interfaceTimerOptionsextendsTaskData{
18-
handleId: number;
18+
handleId?: number;
1919
args: any[];
2020
}
2121

2222
exportfunctionpatchTimer(window: any,setName: string,cancelName: string,nameSuffix: string){
23-
letsetNative: Function=null;
24-
letclearNative: Function=null;
23+
letsetNative: Function|null=null;
24+
letclearNative: 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
returntask;
5555
}
5656

5757
functionclearTask(task: Task){
58-
returnclearNative((<TimerOptions>task.data).handleId);
58+
returnclearNative!((<TimerOptions>task.data).handleId);
5959
}
6060

6161
setNative=
6262
patchMethod(window,setName,(delegate: Function)=>function(self: any,args: any[]){
6363
if(typeofargs[0]==='function'){
6464
constoptions: 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
consttask=
@@ -118,7 +118,7 @@ export function patchTimer(window: any, setName: string, cancelName: string, nam
118118
}
119119
if(task&&typeoftask.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(typeofid==='number'){
123123
deletetasksByHandleId[id];
124124
}elseif(id){

‎lib/common/utils.ts‎

Lines changed: 12 additions & 13 deletions
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
exportfunctionscheduleMacroTaskWithCurrentZone(
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
returnZone.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
letvalue=originalDescGet&&originalDescGet.call(this);
231231
if(value){
232-
desc.set.call(this,value);
232+
desc!.set!.call(this,value);
233233
if(typeoftarget[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-
exportfunctionpatchOnProperties(obj: any,properties: string[],prototype?: any){
245+
exportfunctionpatchOnProperties(obj: any,properties: string[]|null,prototype?: any){
246246
if(properties){
247247
for(leti=0;i<properties.length;i++){
248248
patchProperty(obj,'on'+properties[i],prototype);
@@ -337,7 +337,7 @@ export function patchClass(className: string) {
337337
exportfunctionpatchMethod(
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
letproto=target;
342342
while(proto&&!proto.hasOwnProperty(name)){
343343
proto=ObjectGetPrototypeOf(proto);
@@ -348,14 +348,14 @@ export function patchMethod(
348348
}
349349

350350
constdelegateName=zoneSymbol(name);
351-
letdelegate: Function;
351+
letdelegate: 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
constdesc=proto&&ObjectGetOwnPropertyDescriptor(proto,name);
357357
if(isPropertyWritable(desc)){
358-
constpatchDelegate=patchFn(delegate,delegateName,name);
358+
constpatchDelegate=patchFn(delegate!,delegateName,name);
359359
proto[name]=function(){
360360
returnpatchDelegate(this,argumentsasany);
361361
};
@@ -375,22 +375,21 @@ export interface MacroTaskMeta extends TaskData {
375375
// TODO: @JiaLiPassion, support cancel task later if necessary
376376
exportfunctionpatchMacroTask(
377377
obj: any,funcName: string,metaCreator: (self: any,args: any[])=>MacroTaskMeta){
378-
letsetNative: Function=null;
378+
letsetNative: Function|null=null;
379379

380380
functionscheduleTask(task: Task){
381381
constdata=<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
returntask;
387387
}
388388

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

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

412411
functionscheduleTask(task: Task){
413412
constdata=<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
returntask;
419418
}
420419

‎lib/extra/cordova.ts‎

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

‎lib/extra/electron.ts‎

Lines changed: 1 addition & 1 deletion
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-
functionpatchArguments(target: any,name: string,source: string): Function{
9+
functionpatchArguments(target: any,name: string,source: string): Function|null{
1010
returnapi.patchMethod(target,name,(delegate: Function)=>(self: any,args: any[])=>{
1111
returndelegate&&delegate.apply(self,api.bindArguments(args,source));
1212
});

0 commit comments

Comments
 (0)