@@ -24,7 +24,7 @@ Zone.__load_patch('ZoneAwarePromise', (global: any, Zone: ZoneType, api: _ZonePr
24
24
25
25
interface UncaughtPromiseError extends Error {
26
26
zone : AmbientZone ;
27
- task : Task ;
27
+ task ? : Task ;
28
28
promise : ZoneAwarePromise < any > ;
29
29
rejection : any ;
30
30
}
@@ -53,7 +53,7 @@ Zone.__load_patch('ZoneAwarePromise', (global: any, Zone: ZoneType, api: _ZonePr
53
53
api . microtaskDrainDone = ( ) => {
54
54
while ( _uncaughtPromiseErrors . length ) {
55
55
while ( _uncaughtPromiseErrors . length ) {
56
- const uncaughtPromiseError : UncaughtPromiseError = _uncaughtPromiseErrors . shift ( ) ;
56
+ const uncaughtPromiseError : UncaughtPromiseError = _uncaughtPromiseErrors . shift ( ) ! ;
57
57
try {
58
58
uncaughtPromiseError . zone . runGuarded ( ( ) => {
59
59
throw uncaughtPromiseError ;
@@ -171,7 +171,7 @@ Zone.__load_patch('ZoneAwarePromise', (global: any, Zone: ZoneType, api: _ZonePr
171
171
( promise as any ) [ symbolValue ] = value ;
172
172
173
173
if ( ( promise as any ) [ symbolFinally ] === symbolFinally ) {
174
- // the promise is generated by Promise.prototype.finally
174
+ // the promise is generated by Promise.prototype.finally
175
175
if ( state === RESOLVED ) {
176
176
// the state is resolved, should ignore the value
177
177
// and use parent promise value
@@ -209,7 +209,7 @@ Zone.__load_patch('ZoneAwarePromise', (global: any, Zone: ZoneType, api: _ZonePr
209
209
error . rejection = value ;
210
210
error . promise = promise ;
211
211
error . zone = Zone . current ;
212
- error . task = Zone . currentTask ;
212
+ error . task = Zone . currentTask ! ;
213
213
_uncaughtPromiseErrors . push ( error ) ;
214
214
api . scheduleMicroTask ( ) ; // to make sure that it is running
215
215
}
@@ -246,7 +246,8 @@ Zone.__load_patch('ZoneAwarePromise', (global: any, Zone: ZoneType, api: _ZonePr
246
246
247
247
function scheduleResolveOrReject < R , U1 , U2 > (
248
248
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 {
250
251
clearRejectedNoCatch ( promise ) ;
251
252
const promiseState = ( promise as any ) [ symbolState ] ;
252
253
const delegate = promiseState ?
@@ -255,14 +256,19 @@ Zone.__load_patch('ZoneAwarePromise', (global: any, Zone: ZoneType, api: _ZonePr
255
256
zone . scheduleMicroTask ( source , ( ) => {
256
257
try {
257
258
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 ] ;
259
261
if ( isFinallyPromise ) {
260
262
// if the promise is generated from finally call, keep parent promise's state and value
261
263
( chainPromise as any ) [ symbolParentPromiseValue ] = parentPromiseValue ;
262
264
( chainPromise as any ) [ symbolParentPromiseState ] = promiseState ;
263
265
}
264
266
// 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 ] ) ;
266
272
resolvePromise ( chainPromise , true , value ) ;
267
273
} catch ( error ) {
268
274
// if error occurs, should always return this error
@@ -279,11 +285,11 @@ Zone.__load_patch('ZoneAwarePromise', (global: any, Zone: ZoneType, api: _ZonePr
279
285
}
280
286
281
287
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 ) ;
283
289
}
284
290
285
291
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 ) ;
287
293
}
288
294
289
295
static race < R > ( values : PromiseLike < any > [ ] ) : Promise < R > {
@@ -330,10 +336,10 @@ Zone.__load_patch('ZoneAwarePromise', (global: any, Zone: ZoneType, api: _ZonePr
330
336
resolve ( resolvedValues ) ;
331
337
}
332
338
} ) ( count ) ,
333
- reject ) ;
339
+ reject ! ) ;
334
340
count ++ ;
335
341
}
336
- if ( ! count ) resolve ( resolvedValues ) ;
342
+ if ( ! count ) resolve ! ( resolvedValues ) ;
337
343
return promise ;
338
344
}
339
345
@@ -358,7 +364,7 @@ Zone.__load_patch('ZoneAwarePromise', (global: any, Zone: ZoneType, api: _ZonePr
358
364
onRejected ?: ( ( reason : any ) => TResult2 | PromiseLike < TResult2 > ) | undefined |
359
365
null ) : Promise < TResult1 | TResult2 > {
360
366
const chainPromise : Promise < TResult1 | TResult2 > =
361
- new ( this . constructor as typeof ZoneAwarePromise ) ( null ) ;
367
+ new ( this . constructor as typeof ZoneAwarePromise ) ( null as any ) ;
362
368
const zone = Zone . current ;
363
369
if ( ( this as any ) [ symbolState ] == UNRESOLVED ) {
364
370
( < any [ ] > ( this as any ) [ symbolValue ] ) . push ( zone , chainPromise , onFulfilled , onRejected ) ;
@@ -375,7 +381,7 @@ Zone.__load_patch('ZoneAwarePromise', (global: any, Zone: ZoneType, api: _ZonePr
375
381
376
382
finally < U > ( onFinally ?: ( ) => U | PromiseLike < U > ) : Promise < R > {
377
383
const chainPromise : Promise < R | never > =
378
- new ( this . constructor as typeof ZoneAwarePromise ) ( null ) ;
384
+ new ( this . constructor as typeof ZoneAwarePromise ) ( null as any ) ;
379
385
( chainPromise as any ) [ symbolFinally ] = symbolFinally ;
380
386
const zone = Zone . current ;
381
387
if ( ( this as any ) [ symbolState ] == UNRESOLVED ) {
0 commit comments