Skip to content

Commit b0e37ab

Browse files
committed
Added test for noCustomAsyncPromise switch
1 parent 6e30675 commit b0e37ab

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
tests/cases/conformance/async/es6/noCustomAsyncReturnType_es6.ts(3,5): error TS2529: Duplicate identifier 'Promise'. Compiler reserves name 'Promise' in top level scope of a module containing async functions.
2+
tests/cases/conformance/async/es6/noCustomAsyncReturnType_es6.ts(5,28): error TS1064: The return type of an async function or method must be the global Promise<T> type.
3+
4+
5+
==== tests/cases/conformance/async/es6/noCustomAsyncReturnType_es6.ts (2 errors) ====
6+
7+
interface Promise<T> extends PromiseLike<T> {}
8+
var Promise: PromiseConstructorLike;
9+
~~~~~~~
10+
!!! error TS2529: Duplicate identifier 'Promise'. Compiler reserves name 'Promise' in top level scope of a module containing async functions.
11+
12+
export async function f(): Promise<void> {
13+
~~~~~~~~~~~~~
14+
!!! error TS1064: The return type of an async function or method must be the global Promise<T> type.
15+
}
16+
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//// [noCustomAsyncReturnType_es6.ts]
2+
3+
interface Promise<T> extends PromiseLike<T> {}
4+
var Promise: PromiseConstructorLike;
5+
6+
export async function f(): Promise<void> {
7+
}
8+
9+
10+
//// [noCustomAsyncReturnType_es6.js]
11+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
12+
return new (P || (P = Promise))(function (resolve, reject) {
13+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
14+
function rejected(value) { try { step(generator.throw(value)); } catch (e) { reject(e); } }
15+
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
16+
step((generator = generator.apply(thisArg, _arguments)).next());
17+
});
18+
};
19+
var Promise;
20+
export function f() {
21+
return __awaiter(this, void 0, void 0, function* () {
22+
});
23+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// @target: ES6
2+
// @noCustomAsyncPromise: true
3+
4+
interface Promise<T> extends PromiseLike<T> {}
5+
var Promise: PromiseConstructorLike;
6+
7+
export async function f(): Promise<void> {
8+
}

0 commit comments

Comments
 (0)