@@ -50,16 +50,16 @@ Zone.__load_patch('ZoneAwarePromise', (global: any, Zone: ZoneType, api: _ZonePr
50
50
51
51
const UNHANDLED_PROMISE_REJECTION_HANDLER_SYMBOL = __symbol__ ( 'unhandledPromiseRejectionHandler' ) ;
52
52
53
- function handleUnhandledRejection ( e : any ) {
54
- api . onUnhandledError ( e ) ;
55
- try {
56
- const handler = ( Zone as any ) [ UNHANDLED_PROMISE_REJECTION_HANDLER_SYMBOL ] ;
57
- if ( handler && typeof handler === 'function' ) {
58
- handler . apply ( this , [ e ] ) ;
53
+ function handleUnhandledRejection ( e : any ) {
54
+ api . onUnhandledError ( e ) ;
55
+ try {
56
+ const handler = ( Zone as any ) [ UNHANDLED_PROMISE_REJECTION_HANDLER_SYMBOL ] ;
57
+ if ( handler && typeof handler === 'function' ) {
58
+ handler . apply ( this , [ e ] ) ;
59
+ }
60
+ } catch ( err ) {
59
61
}
60
- } catch ( err ) {
61
62
}
62
- }
63
63
64
64
function isThenable ( value : any ) : boolean {
65
65
return value && value . then ;
@@ -207,13 +207,14 @@ Zone.__load_patch('ZoneAwarePromise', (global: any, Zone: ZoneType, api: _ZonePr
207
207
}
208
208
}
209
209
210
- function scheduleResolveOrReject < R , U > (
211
- promise : ZoneAwarePromise < any > , zone : AmbientZone , chainPromise : ZoneAwarePromise < any > ,
212
- onFulfilled ?: ( value : R ) => U , onRejected ?: ( error : any ) => U ) : void {
210
+ function scheduleResolveOrReject < R , U1 , U2 > (
211
+ promise : ZoneAwarePromise < any > , zone : AmbientZone ,
212
+ chainPromise : ZoneAwarePromise < any > , onFulfilled ?: ( value : R ) => U1 ,
213
+ onRejected ?: ( error : any ) => U2 ) : void {
213
214
clearRejectedNoCatch ( promise ) ;
214
215
const delegate = ( promise as any ) [ symbolState ] ?
215
- ( typeof onFulfilled === FUNCTION ) ? onFulfilled : forwardResolution :
216
- ( typeof onRejected === FUNCTION ) ? onRejected : forwardRejection ;
216
+ ( typeof onFulfilled === FUNCTION ) ? onFulfilled : forwardResolution :
217
+ ( typeof onRejected === FUNCTION ) ? onRejected : forwardRejection ;
217
218
zone . scheduleMicroTask ( source , ( ) => {
218
219
try {
219
220
resolvePromise (
@@ -265,7 +266,7 @@ Zone.__load_patch('ZoneAwarePromise', (global: any, Zone: ZoneType, api: _ZonePr
265
266
static all < R > ( values : any ) : Promise < R > {
266
267
let resolve : ( v : any ) => void ;
267
268
let reject : ( v : any ) => void ;
268
- let promise = new this ( ( res , rej ) => {
269
+ let promise = new this < R > ( ( res , rej ) => {
269
270
resolve = res ;
270
271
reject = rej ;
271
272
} ) ;
@@ -306,10 +307,13 @@ Zone.__load_patch('ZoneAwarePromise', (global: any, Zone: ZoneType, api: _ZonePr
306
307
}
307
308
}
308
309
309
- then < R , U > (
310
- onFulfilled ?: ( value : R ) => U | PromiseLike < U > ,
311
- onRejected ?: ( error : any ) => U | PromiseLike < U > ) : Promise < R > {
312
- const chainPromise : Promise < R > = new ( this . constructor as typeof ZoneAwarePromise ) ( null ) ;
310
+ then < TResult1 = R , TResult2 = never > (
311
+ onFulfilled ?: ( ( value : R ) => TResult1 | PromiseLike < TResult1 > ) |
312
+ undefined | null ,
313
+ onRejected ?: ( ( reason : any ) => TResult2 | PromiseLike < TResult2 > ) |
314
+ undefined | null ) : Promise < TResult1 | TResult2 > {
315
+ const chainPromise : Promise < TResult1 | TResult2 > =
316
+ new ( this . constructor as typeof ZoneAwarePromise ) ( null ) ;
313
317
const zone = Zone . current ;
314
318
if ( ( this as any ) [ symbolState ] == UNRESOLVED ) {
315
319
( < any [ ] > ( this as any ) [ symbolValue ] ) . push ( zone , chainPromise , onFulfilled , onRejected ) ;
@@ -319,7 +323,9 @@ Zone.__load_patch('ZoneAwarePromise', (global: any, Zone: ZoneType, api: _ZonePr
319
323
return chainPromise ;
320
324
}
321
325
322
- catch < U > ( onRejected ?: ( error : any ) => U | PromiseLike < U > ) : Promise < R > {
326
+ catch < TResult = never > (
327
+ onRejected ?: ( ( reason : any ) => TResult | PromiseLike < TResult > ) |
328
+ undefined | null ) : Promise < R | TResult > {
323
329
return this . then ( null , onRejected ) ;
324
330
}
325
331
}
@@ -333,43 +339,43 @@ Zone.__load_patch('ZoneAwarePromise', (global: any, Zone: ZoneType, api: _ZonePr
333
339
const NativePromise = global [ symbolPromise ] = global [ 'Promise' ] ;
334
340
const ZONE_AWARE_PROMISE = Zone . __symbol__ ( 'ZoneAwarePromise' ) ;
335
341
336
- let desc = Object . getOwnPropertyDescriptor ( global , 'Promise' ) ;
337
- if ( ! desc || desc . configurable ) {
338
- desc && delete desc . writable ;
339
- desc && delete desc . value ;
340
- if ( ! desc ) {
341
- desc = { configurable : true , enumerable : true } ;
342
- }
343
- desc . get = function ( ) {
344
- // if we already set ZoneAwarePromise, use patched one
345
- // otherwise return native one.
346
- return global [ ZONE_AWARE_PROMISE ] ? global [ ZONE_AWARE_PROMISE ] : global [ symbolPromise ] ;
347
- } ;
348
- desc . set = function ( NewNativePromise ) {
349
- if ( NewNativePromise === ZoneAwarePromise ) {
350
- // if the NewNativePromise is ZoneAwarePromise
351
- // save to global
352
- global [ ZONE_AWARE_PROMISE ] = NewNativePromise ;
353
- } else {
354
- // if the NewNativePromise is not ZoneAwarePromise
355
- // for example: after load zone.js, some library just
356
- // set es6-promise to global, if we set it to global
357
- // directly, assertZonePatched will fail and angular
358
- // will not loaded, so we just set the NewNativePromise
359
- // to global[symbolPromise], so the result is just like
360
- // we load ES6 Promise before zone.js
361
- global [ symbolPromise ] = NewNativePromise ;
362
- if ( ! NewNativePromise . prototype [ symbolThen ] ) {
363
- patchThen ( NewNativePromise ) ;
364
- }
365
- api . setNativePromise ( NewNativePromise ) ;
342
+ let desc = Object . getOwnPropertyDescriptor ( global , 'Promise' ) ;
343
+ if ( ! desc || desc . configurable ) {
344
+ desc && delete desc . writable ;
345
+ desc && delete desc . value ;
346
+ if ( ! desc ) {
347
+ desc = { configurable : true , enumerable : true } ;
366
348
}
367
- } ;
349
+ desc . get = function ( ) {
350
+ // if we already set ZoneAwarePromise, use patched one
351
+ // otherwise return native one.
352
+ return global [ ZONE_AWARE_PROMISE ] ? global [ ZONE_AWARE_PROMISE ] : global [ symbolPromise ] ;
353
+ } ;
354
+ desc . set = function ( NewNativePromise ) {
355
+ if ( NewNativePromise === ZoneAwarePromise ) {
356
+ // if the NewNativePromise is ZoneAwarePromise
357
+ // save to global
358
+ global [ ZONE_AWARE_PROMISE ] = NewNativePromise ;
359
+ } else {
360
+ // if the NewNativePromise is not ZoneAwarePromise
361
+ // for example: after load zone.js, some library just
362
+ // set es6-promise to global, if we set it to global
363
+ // directly, assertZonePatched will fail and angular
364
+ // will not loaded, so we just set the NewNativePromise
365
+ // to global[symbolPromise], so the result is just like
366
+ // we load ES6 Promise before zone.js
367
+ global [ symbolPromise ] = NewNativePromise ;
368
+ if ( ! NewNativePromise . prototype [ symbolThen ] ) {
369
+ patchThen ( NewNativePromise ) ;
370
+ }
371
+ api . setNativePromise ( NewNativePromise ) ;
372
+ }
373
+ } ;
368
374
369
- Object . defineProperty ( global , 'Promise' , desc ) ;
370
- }
375
+ Object . defineProperty ( global , 'Promise' , desc ) ;
376
+ }
371
377
372
- global [ 'Promise' ] = ZoneAwarePromise ;
378
+ global [ 'Promise' ] = ZoneAwarePromise ;
373
379
374
380
const symbolThenPatched = __symbol__ ( 'thenPatched' ) ;
375
381
0 commit comments