@@ -50,16 +50,16 @@ Zone.__load_patch('ZoneAwarePromise', (global: any, Zone: ZoneType, api: _ZonePr
5050
5151 const UNHANDLED_PROMISE_REJECTION_HANDLER_SYMBOL = __symbol__ ( 'unhandledPromiseRejectionHandler' ) ;
5252
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 ) {
5961 }
60- } catch ( err ) {
6162 }
62- }
6363
6464 function isThenable ( value : any ) : boolean {
6565 return value && value . then ;
@@ -207,13 +207,14 @@ Zone.__load_patch('ZoneAwarePromise', (global: any, Zone: ZoneType, api: _ZonePr
207207 }
208208 }
209209
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 {
213214 clearRejectedNoCatch ( promise ) ;
214215 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 ;
217218 zone . scheduleMicroTask ( source , ( ) => {
218219 try {
219220 resolvePromise (
@@ -265,7 +266,7 @@ Zone.__load_patch('ZoneAwarePromise', (global: any, Zone: ZoneType, api: _ZonePr
265266 static all < R > ( values : any ) : Promise < R > {
266267 let resolve : ( v : any ) => void ;
267268 let reject : ( v : any ) => void ;
268- let promise = new this ( ( res , rej ) => {
269+ let promise = new this < R > ( ( res , rej ) => {
269270 resolve = res ;
270271 reject = rej ;
271272 } ) ;
@@ -306,10 +307,13 @@ Zone.__load_patch('ZoneAwarePromise', (global: any, Zone: ZoneType, api: _ZonePr
306307 }
307308 }
308309
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 ) ;
313317 const zone = Zone . current ;
314318 if ( ( this as any ) [ symbolState ] == UNRESOLVED ) {
315319 ( < any [ ] > ( this as any ) [ symbolValue ] ) . push ( zone , chainPromise , onFulfilled , onRejected ) ;
@@ -319,7 +323,9 @@ Zone.__load_patch('ZoneAwarePromise', (global: any, Zone: ZoneType, api: _ZonePr
319323 return chainPromise ;
320324 }
321325
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 > {
323329 return this . then ( null , onRejected ) ;
324330 }
325331 }
@@ -333,43 +339,43 @@ Zone.__load_patch('ZoneAwarePromise', (global: any, Zone: ZoneType, api: _ZonePr
333339 const NativePromise = global [ symbolPromise ] = global [ 'Promise' ] ;
334340 const ZONE_AWARE_PROMISE = Zone . __symbol__ ( 'ZoneAwarePromise' ) ;
335341
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 } ;
366348 }
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+ } ;
368374
369- Object . defineProperty ( global , 'Promise' , desc ) ;
370- }
375+ Object . defineProperty ( global , 'Promise' , desc ) ;
376+ }
371377
372- global [ 'Promise' ] = ZoneAwarePromise ;
378+ global [ 'Promise' ] = ZoneAwarePromise ;
373379
374380 const symbolThenPatched = __symbol__ ( 'thenPatched' ) ;
375381
0 commit comments