Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.

Commit 47dd3f4

Browse files
JiaLiPassionvikerman
authored andcommitted
fix: remove finally definition from Promise interface, will use es2018.promise in the future (#1204)
1 parent c378f87 commit 47dd3f4

File tree

2 files changed

+19
-21
lines changed

2 files changed

+19
-21
lines changed

Diff for: lib/common/promise.ts

+3-7
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@
55
* Use of this source code is governed by an MIT-style license that can be
66
* found in the LICENSE file at https://angular.io/license
77
*/
8-
interface Promise<T> {
9-
finally<U>(onFinally?: () => U | PromiseLike<U>): Promise<T>;
10-
}
11-
128
Zone.__load_patch('ZoneAwarePromise', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
139
const ObjectGetOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
1410
const ObjectDefineProperty = Object.defineProperty;
@@ -146,7 +142,7 @@ Zone.__load_patch('ZoneAwarePromise', (global: any, Zone: ZoneType, api: _ZonePr
146142
if (state !== REJECTED && value instanceof ZoneAwarePromise &&
147143
value.hasOwnProperty(symbolState) && value.hasOwnProperty(symbolValue) &&
148144
(value as any)[symbolState] !== UNRESOLVED) {
149-
clearRejectedNoCatch(<Promise<any>>value);
145+
clearRejectedNoCatch(<Promise<any>>value as any);
150146
resolvePromise(promise, (value as any)[symbolState], (value as any)[symbolValue]);
151147
} else if (state !== REJECTED && typeof then === 'function') {
152148
try {
@@ -379,7 +375,7 @@ Zone.__load_patch('ZoneAwarePromise', (global: any, Zone: ZoneType, api: _ZonePr
379375
if ((this as any)[symbolState] == UNRESOLVED) {
380376
(<any[]>(this as any)[symbolValue]).push(zone, chainPromise, onFulfilled, onRejected);
381377
} else {
382-
scheduleResolveOrReject(this, zone, chainPromise, onFulfilled, onRejected);
378+
scheduleResolveOrReject(this, zone, chainPromise as any, onFulfilled, onRejected);
383379
}
384380
return chainPromise;
385381
}
@@ -397,7 +393,7 @@ Zone.__load_patch('ZoneAwarePromise', (global: any, Zone: ZoneType, api: _ZonePr
397393
if ((this as any)[symbolState] == UNRESOLVED) {
398394
(<any[]>(this as any)[symbolValue]).push(zone, chainPromise, onFinally, onFinally);
399395
} else {
400-
scheduleResolveOrReject(this, zone, chainPromise, onFinally, onFinally);
396+
scheduleResolveOrReject(this, zone, chainPromise as any, onFinally, onFinally);
401397
}
402398
return chainPromise;
403399
}

Diff for: test/common/Promise.spec.ts

+16-14
Original file line numberDiff line numberDiff line change
@@ -219,13 +219,14 @@ describe(
219219
let resolve: Function|null = null;
220220

221221
testZone.run(function() {
222-
new Promise(function(resolveFn) {
223-
resolve = resolveFn;
224-
}).finally(function() {
225-
expect(arguments.length).toBe(0);
226-
expect(Zone.current).toBe(testZone);
227-
done();
228-
});
222+
(new Promise(function(resolveFn) {
223+
resolve = resolveFn;
224+
}) as any)
225+
.finally(function() {
226+
expect(arguments.length).toBe(0);
227+
expect(Zone.current).toBe(testZone);
228+
done();
229+
});
229230
});
230231

231232
resolve!('value');
@@ -235,13 +236,14 @@ describe(
235236
let reject: Function|null = null;
236237

237238
testZone.run(function() {
238-
new Promise(function(_, rejectFn) {
239-
reject = rejectFn;
240-
}).finally(function() {
241-
expect(arguments.length).toBe(0);
242-
expect(Zone.current).toBe(testZone);
243-
done();
244-
});
239+
(new Promise(function(_, rejectFn) {
240+
reject = rejectFn;
241+
}) as any)
242+
.finally(function() {
243+
expect(arguments.length).toBe(0);
244+
expect(Zone.current).toBe(testZone);
245+
done();
246+
});
245247
});
246248

247249
reject!('error');

0 commit comments

Comments
 (0)