Skip to content

Commit

Permalink
Upgrade to typescript 2.5.2
Browse files Browse the repository at this point in the history
Due to stricter generic type checks, signatures for ZoneAwarePromise
need to be changed. See
microsoft/TypeScript#16368

The signatures from lib.es5.d.ts were copied over for .then and .catch.
  • Loading branch information
rkirov committed Oct 11, 2017
1 parent 326a07f commit 85cf3e3
Show file tree
Hide file tree
Showing 4 changed files with 3,227 additions and 2,860 deletions.
24 changes: 15 additions & 9 deletions lib/common/promise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,10 @@ Zone.__load_patch('ZoneAwarePromise', (global: any, Zone: ZoneType, api: _ZonePr
}
}

function scheduleResolveOrReject<R, U>(
promise: ZoneAwarePromise<any>, zone: AmbientZone, chainPromise: ZoneAwarePromise<any>,
onFulfilled?: (value: R) => U, onRejected?: (error: any) => U): void {
function scheduleResolveOrReject<R, U1, U2>(
promise: ZoneAwarePromise<any>, zone: AmbientZone,
chainPromise: ZoneAwarePromise<any>, onFulfilled?: (value: R) => U1,
onRejected?: (error: any) => U2): void {
clearRejectedNoCatch(promise);
const delegate = (promise as any)[symbolState] ?
(typeof onFulfilled === FUNCTION) ? onFulfilled : forwardResolution :
Expand Down Expand Up @@ -265,7 +266,7 @@ Zone.__load_patch('ZoneAwarePromise', (global: any, Zone: ZoneType, api: _ZonePr
static all<R>(values: any): Promise<R> {
let resolve: (v: any) => void;
let reject: (v: any) => void;
let promise = new this((res, rej) => {
let promise = new this<R>((res, rej) => {
resolve = res;
reject = rej;
});
Expand Down Expand Up @@ -306,10 +307,13 @@ Zone.__load_patch('ZoneAwarePromise', (global: any, Zone: ZoneType, api: _ZonePr
}
}

then<R, U>(
onFulfilled?: (value: R) => U | PromiseLike<U>,
onRejected?: (error: any) => U | PromiseLike<U>): Promise<R> {
const chainPromise: Promise<R> = new (this.constructor as typeof ZoneAwarePromise)(null);
then<TResult1 = R, TResult2 = never>(
onFulfilled?: ((value: R) => TResult1 | PromiseLike<TResult1>)|
undefined|null,
onRejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>)|
undefined|null): Promise<TResult1|TResult2> {
const chainPromise: Promise<TResult1|TResult2> =
new (this.constructor as typeof ZoneAwarePromise)(null);
const zone = Zone.current;
if ((this as any)[symbolState] == UNRESOLVED) {
(<any[]>(this as any)[symbolValue]).push(zone, chainPromise, onFulfilled, onRejected);
Expand All @@ -319,7 +323,9 @@ Zone.__load_patch('ZoneAwarePromise', (global: any, Zone: ZoneType, api: _ZonePr
return chainPromise;
}

catch<U>(onRejected?: (error: any) => U | PromiseLike<U>): Promise<R> {
catch<TResult = never>(
onRejected?: ((reason: any) => TResult | PromiseLike<TResult>)|
undefined|null): Promise<R|TResult> {
return this.then(null, onRejected);
}
}
Expand Down
Loading

0 comments on commit 85cf3e3

Please sign in to comment.