mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Merge pull request #6967 from Microsoft/revertNoCustomPromise
Revert restrictions on custom Promise in async function return type
This commit is contained in:
@@ -12623,7 +12623,7 @@ namespace ts {
|
||||
* callable `then` signature.
|
||||
*/
|
||||
function checkAsyncFunctionReturnType(node: FunctionLikeDeclaration): Type {
|
||||
if (languageVersion >= ScriptTarget.ES6) {
|
||||
if (compilerOptions.noCustomAsyncPromise && languageVersion >= ScriptTarget.ES6) {
|
||||
const returnType = getTypeFromTypeNode(node.type);
|
||||
return checkCorrectPromiseType(returnType, node.type);
|
||||
}
|
||||
@@ -13029,6 +13029,10 @@ namespace ts {
|
||||
}
|
||||
|
||||
function checkCollisionWithGlobalPromiseInGeneratedCode(node: Node, name: Identifier): void {
|
||||
if (!compilerOptions.noCustomAsyncPromise) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!needCollisionCheckForIdentifier(node, name, "Promise")) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -299,6 +299,11 @@ namespace ts {
|
||||
name: "noImplicitUseStrict",
|
||||
type: "boolean",
|
||||
description: Diagnostics.Do_not_emit_use_strict_directives_in_module_output
|
||||
},
|
||||
{
|
||||
name: "noCustomAsyncPromise",
|
||||
type: "boolean",
|
||||
experimental: true
|
||||
}
|
||||
];
|
||||
|
||||
|
||||
@@ -296,11 +296,11 @@ namespace ts {
|
||||
* If loop contains block scoped binding captured in some function then loop body is converted to a function.
|
||||
* Lexical bindings declared in loop initializer will be passed into the loop body function as parameters,
|
||||
* however if this binding is modified inside the body - this new value should be propagated back to the original binding.
|
||||
* This is done by declaring new variable (out parameter holder) outside of the loop for every binding that is reassigned inside the body.
|
||||
* This is done by declaring new variable (out parameter holder) outside of the loop for every binding that is reassigned inside the body.
|
||||
* On every iteration this variable is initialized with value of corresponding binding.
|
||||
* At every point where control flow leaves the loop either explicitly (break/continue) or implicitly (at the end of loop body)
|
||||
* we copy the value inside the loop to the out parameter holder.
|
||||
*
|
||||
*
|
||||
* for (let x;;) {
|
||||
* let a = 1;
|
||||
* let b = () => a;
|
||||
@@ -308,9 +308,9 @@ namespace ts {
|
||||
* if (...) break;
|
||||
* ...
|
||||
* }
|
||||
*
|
||||
*
|
||||
* will be converted to
|
||||
*
|
||||
*
|
||||
* var out_x;
|
||||
* var loop = function(x) {
|
||||
* var a = 1;
|
||||
@@ -326,7 +326,7 @@ namespace ts {
|
||||
* x = out_x;
|
||||
* if (state === "break") break;
|
||||
* }
|
||||
*
|
||||
*
|
||||
* NOTE: values to out parameters are not copies if loop is abrupted with 'return' - in this case this will end the entire enclosing function
|
||||
* so nobody can observe this new value.
|
||||
*/
|
||||
@@ -3049,7 +3049,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
||||
}
|
||||
|
||||
writeLine();
|
||||
// end of loop body -> copy out parameter
|
||||
// end of loop body -> copy out parameter
|
||||
copyLoopOutParameters(convertedLoopState, CopyDirection.ToOutParameter, /*emitAsStatements*/true);
|
||||
|
||||
decreaseIndent();
|
||||
@@ -4685,7 +4685,7 @@ const _super = (function (geti, seti) {
|
||||
write(", void 0, ");
|
||||
}
|
||||
|
||||
if (languageVersion >= ScriptTarget.ES6 || !promiseConstructor) {
|
||||
if (!promiseConstructor || (compilerOptions.noCustomAsyncPromise && languageVersion >= ScriptTarget.ES6)) {
|
||||
write("void 0");
|
||||
}
|
||||
else {
|
||||
@@ -7245,7 +7245,7 @@ const _super = (function (geti, seti) {
|
||||
}
|
||||
|
||||
// text should be quoted string
|
||||
// for deduplication purposes in key remove leading and trailing quotes so 'a' and "a" will be considered the same
|
||||
// for deduplication purposes in key remove leading and trailing quotes so 'a' and "a" will be considered the same
|
||||
const key = text.substr(1, text.length - 2);
|
||||
|
||||
if (hasProperty(groupIndices, key)) {
|
||||
|
||||
@@ -2442,6 +2442,8 @@ namespace ts {
|
||||
/* @internal */ skipDefaultLibCheck?: boolean;
|
||||
// Do not perform validation of output file name in transpile scenarios
|
||||
/* @internal */ suppressOutputPathCheck?: boolean;
|
||||
// Disallow custom promise return types in async functions.
|
||||
/* @internal */ noCustomAsyncPromise?: boolean;
|
||||
|
||||
[option: string]: string | number | boolean;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
tests/cases/conformance/async/es6/asyncAliasReturnType_es6.ts(3,16): error TS1055: Type 'PromiseAlias' is not a valid async function return type.
|
||||
|
||||
|
||||
==== tests/cases/conformance/async/es6/asyncAliasReturnType_es6.ts (1 errors) ====
|
||||
type PromiseAlias<T> = Promise<T>;
|
||||
|
||||
async function f(): PromiseAlias<void> {
|
||||
~
|
||||
!!! error TS1055: Type 'PromiseAlias' is not a valid async function return type.
|
||||
}
|
||||
@@ -6,6 +6,6 @@ async function f(): PromiseAlias<void> {
|
||||
|
||||
//// [asyncAliasReturnType_es6.js]
|
||||
function f() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
return __awaiter(this, void 0, PromiseAlias, function* () {
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
=== tests/cases/conformance/async/es6/asyncAliasReturnType_es6.ts ===
|
||||
type PromiseAlias<T> = Promise<T>;
|
||||
>PromiseAlias : Symbol(PromiseAlias, Decl(asyncAliasReturnType_es6.ts, 0, 0))
|
||||
>T : Symbol(T, Decl(asyncAliasReturnType_es6.ts, 0, 18))
|
||||
>Promise : Symbol(Promise, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
|
||||
>T : Symbol(T, Decl(asyncAliasReturnType_es6.ts, 0, 18))
|
||||
|
||||
async function f(): PromiseAlias<void> {
|
||||
>f : Symbol(f, Decl(asyncAliasReturnType_es6.ts, 0, 34))
|
||||
>PromiseAlias : Symbol(PromiseAlias, Decl(asyncAliasReturnType_es6.ts, 0, 0))
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
=== tests/cases/conformance/async/es6/asyncAliasReturnType_es6.ts ===
|
||||
type PromiseAlias<T> = Promise<T>;
|
||||
>PromiseAlias : Promise<T>
|
||||
>T : T
|
||||
>Promise : Promise<T>
|
||||
>T : T
|
||||
|
||||
async function f(): PromiseAlias<void> {
|
||||
>f : () => Promise<void>
|
||||
>PromiseAlias : Promise<T>
|
||||
}
|
||||
@@ -4,5 +4,5 @@ var foo = async (): Promise<void> => {
|
||||
};
|
||||
|
||||
//// [asyncArrowFunction1_es6.js]
|
||||
var foo = () => __awaiter(this, void 0, void 0, function* () {
|
||||
var foo = () => __awaiter(this, void 0, Promise, function* () {
|
||||
});
|
||||
|
||||
@@ -4,5 +4,5 @@ var foo = async (a = await): Promise<void> => {
|
||||
}
|
||||
|
||||
//// [asyncArrowFunction6_es6.js]
|
||||
var foo = (a = yield ) => __awaiter(this, void 0, void 0, function* () {
|
||||
var foo = (a = yield ) => __awaiter(this, void 0, Promise, function* () {
|
||||
});
|
||||
|
||||
@@ -7,8 +7,8 @@ var bar = async (): Promise<void> => {
|
||||
}
|
||||
|
||||
//// [asyncArrowFunction7_es6.js]
|
||||
var bar = () => __awaiter(this, void 0, void 0, function* () {
|
||||
var bar = () => __awaiter(this, void 0, Promise, function* () {
|
||||
// 'await' here is an identifier, and not an await expression.
|
||||
var foo = (a = yield ) => __awaiter(this, void 0, void 0, function* () {
|
||||
var foo = (a = yield ) => __awaiter(this, void 0, Promise, function* () {
|
||||
});
|
||||
});
|
||||
|
||||
@@ -5,6 +5,6 @@ var foo = async (): Promise<void> => {
|
||||
}
|
||||
|
||||
//// [asyncArrowFunction8_es6.js]
|
||||
var foo = () => __awaiter(this, void 0, void 0, function* () {
|
||||
var foo = () => __awaiter(this, void 0, Promise, function* () {
|
||||
var v = { [yield ]: foo };
|
||||
});
|
||||
|
||||
@@ -52,36 +52,36 @@ function f0() {
|
||||
return __awaiter(this, void 0, void 0, function* () { });
|
||||
}
|
||||
function f1() {
|
||||
return __awaiter(this, void 0, void 0, function* () { });
|
||||
return __awaiter(this, void 0, Promise, function* () { });
|
||||
}
|
||||
function f3() {
|
||||
return __awaiter(this, void 0, void 0, function* () { });
|
||||
return __awaiter(this, void 0, MyPromise, function* () { });
|
||||
}
|
||||
let f4 = function () {
|
||||
return __awaiter(this, void 0, void 0, function* () { });
|
||||
};
|
||||
let f5 = function () {
|
||||
return __awaiter(this, void 0, void 0, function* () { });
|
||||
return __awaiter(this, void 0, Promise, function* () { });
|
||||
};
|
||||
let f6 = function () {
|
||||
return __awaiter(this, void 0, void 0, function* () { });
|
||||
return __awaiter(this, void 0, MyPromise, function* () { });
|
||||
};
|
||||
let f7 = () => __awaiter(this, void 0, void 0, function* () { });
|
||||
let f8 = () => __awaiter(this, void 0, void 0, function* () { });
|
||||
let f9 = () => __awaiter(this, void 0, void 0, function* () { });
|
||||
let f8 = () => __awaiter(this, void 0, Promise, function* () { });
|
||||
let f9 = () => __awaiter(this, void 0, MyPromise, function* () { });
|
||||
let f10 = () => __awaiter(this, void 0, void 0, function* () { return p; });
|
||||
let f11 = () => __awaiter(this, void 0, void 0, function* () { return mp; });
|
||||
let f12 = () => __awaiter(this, void 0, void 0, function* () { return mp; });
|
||||
let f13 = () => __awaiter(this, void 0, void 0, function* () { return p; });
|
||||
let f12 = () => __awaiter(this, void 0, Promise, function* () { return mp; });
|
||||
let f13 = () => __awaiter(this, void 0, MyPromise, function* () { return p; });
|
||||
let o = {
|
||||
m1() {
|
||||
return __awaiter(this, void 0, void 0, function* () { });
|
||||
},
|
||||
m2() {
|
||||
return __awaiter(this, void 0, void 0, function* () { });
|
||||
return __awaiter(this, void 0, Promise, function* () { });
|
||||
},
|
||||
m3() {
|
||||
return __awaiter(this, void 0, void 0, function* () { });
|
||||
return __awaiter(this, void 0, MyPromise, function* () { });
|
||||
}
|
||||
};
|
||||
class C {
|
||||
@@ -89,19 +89,19 @@ class C {
|
||||
return __awaiter(this, void 0, void 0, function* () { });
|
||||
}
|
||||
m2() {
|
||||
return __awaiter(this, void 0, void 0, function* () { });
|
||||
return __awaiter(this, void 0, Promise, function* () { });
|
||||
}
|
||||
m3() {
|
||||
return __awaiter(this, void 0, void 0, function* () { });
|
||||
return __awaiter(this, void 0, MyPromise, function* () { });
|
||||
}
|
||||
static m4() {
|
||||
return __awaiter(this, void 0, void 0, function* () { });
|
||||
}
|
||||
static m5() {
|
||||
return __awaiter(this, void 0, void 0, function* () { });
|
||||
return __awaiter(this, void 0, Promise, function* () { });
|
||||
}
|
||||
static m6() {
|
||||
return __awaiter(this, void 0, void 0, function* () { });
|
||||
return __awaiter(this, void 0, MyPromise, function* () { });
|
||||
}
|
||||
}
|
||||
var M;
|
||||
|
||||
@@ -52,36 +52,36 @@ function f0() {
|
||||
return __awaiter(this, void 0, void 0, function* () { });
|
||||
}
|
||||
function f1() {
|
||||
return __awaiter(this, void 0, void 0, function* () { });
|
||||
return __awaiter(this, void 0, Promise, function* () { });
|
||||
}
|
||||
function f3() {
|
||||
return __awaiter(this, void 0, void 0, function* () { });
|
||||
return __awaiter(this, void 0, MyPromise, function* () { });
|
||||
}
|
||||
let f4 = function () {
|
||||
return __awaiter(this, void 0, void 0, function* () { });
|
||||
};
|
||||
let f5 = function () {
|
||||
return __awaiter(this, void 0, void 0, function* () { });
|
||||
return __awaiter(this, void 0, Promise, function* () { });
|
||||
};
|
||||
let f6 = function () {
|
||||
return __awaiter(this, void 0, void 0, function* () { });
|
||||
return __awaiter(this, void 0, MyPromise, function* () { });
|
||||
};
|
||||
let f7 = () => __awaiter(this, void 0, void 0, function* () { });
|
||||
let f8 = () => __awaiter(this, void 0, void 0, function* () { });
|
||||
let f9 = () => __awaiter(this, void 0, void 0, function* () { });
|
||||
let f8 = () => __awaiter(this, void 0, Promise, function* () { });
|
||||
let f9 = () => __awaiter(this, void 0, MyPromise, function* () { });
|
||||
let f10 = () => __awaiter(this, void 0, void 0, function* () { return p; });
|
||||
let f11 = () => __awaiter(this, void 0, void 0, function* () { return mp; });
|
||||
let f12 = () => __awaiter(this, void 0, void 0, function* () { return mp; });
|
||||
let f13 = () => __awaiter(this, void 0, void 0, function* () { return p; });
|
||||
let f12 = () => __awaiter(this, void 0, Promise, function* () { return mp; });
|
||||
let f13 = () => __awaiter(this, void 0, MyPromise, function* () { return p; });
|
||||
let o = {
|
||||
m1() {
|
||||
return __awaiter(this, void 0, void 0, function* () { });
|
||||
},
|
||||
m2() {
|
||||
return __awaiter(this, void 0, void 0, function* () { });
|
||||
return __awaiter(this, void 0, Promise, function* () { });
|
||||
},
|
||||
m3() {
|
||||
return __awaiter(this, void 0, void 0, function* () { });
|
||||
return __awaiter(this, void 0, MyPromise, function* () { });
|
||||
}
|
||||
};
|
||||
class C {
|
||||
@@ -89,19 +89,19 @@ class C {
|
||||
return __awaiter(this, void 0, void 0, function* () { });
|
||||
}
|
||||
m2() {
|
||||
return __awaiter(this, void 0, void 0, function* () { });
|
||||
return __awaiter(this, void 0, Promise, function* () { });
|
||||
}
|
||||
m3() {
|
||||
return __awaiter(this, void 0, void 0, function* () { });
|
||||
return __awaiter(this, void 0, MyPromise, function* () { });
|
||||
}
|
||||
static m4() {
|
||||
return __awaiter(this, void 0, void 0, function* () { });
|
||||
}
|
||||
static m5() {
|
||||
return __awaiter(this, void 0, void 0, function* () { });
|
||||
return __awaiter(this, void 0, Promise, function* () { });
|
||||
}
|
||||
static m6() {
|
||||
return __awaiter(this, void 0, void 0, function* () { });
|
||||
return __awaiter(this, void 0, MyPromise, function* () { });
|
||||
}
|
||||
}
|
||||
var M;
|
||||
|
||||
@@ -4,6 +4,6 @@ async function await(): Promise<void> {
|
||||
|
||||
//// [asyncFunctionDeclaration11_es6.js]
|
||||
function await() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
return __awaiter(this, void 0, Promise, function* () {
|
||||
});
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ async function foo(): Promise<void> {
|
||||
|
||||
//// [asyncFunctionDeclaration13_es6.js]
|
||||
function foo() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
return __awaiter(this, void 0, Promise, function* () {
|
||||
// Legal to use 'await' in a type context.
|
||||
var v;
|
||||
});
|
||||
|
||||
@@ -5,7 +5,7 @@ async function foo(): Promise<void> {
|
||||
|
||||
//// [asyncFunctionDeclaration14_es6.js]
|
||||
function foo() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
return __awaiter(this, void 0, Promise, function* () {
|
||||
return;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,33 +1,44 @@
|
||||
tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration15_es6.ts(6,23): error TS1064: The return type of an async function or method must be the global Promise<T> type.
|
||||
tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration15_es6.ts(7,23): error TS1064: The return type of an async function or method must be the global Promise<T> type.
|
||||
tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration15_es6.ts(8,23): error TS1064: The return type of an async function or method must be the global Promise<T> type.
|
||||
tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration15_es6.ts(9,23): error TS1064: The return type of an async function or method must be the global Promise<T> type.
|
||||
tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration15_es6.ts(10,23): error TS1064: The return type of an async function or method must be the global Promise<T> type.
|
||||
tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration15_es6.ts(6,16): error TS1055: Type '{}' is not a valid async function return type.
|
||||
tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration15_es6.ts(7,16): error TS1055: Type 'any' is not a valid async function return type.
|
||||
tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration15_es6.ts(8,16): error TS1055: Type 'number' is not a valid async function return type.
|
||||
tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration15_es6.ts(9,16): error TS1055: Type 'PromiseLike' is not a valid async function return type.
|
||||
tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration15_es6.ts(10,16): error TS1055: Type 'typeof Thenable' is not a valid async function return type.
|
||||
tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration15_es6.ts(10,16): error TS1055: Type 'typeof Thenable' is not a valid async function return type.
|
||||
Type 'Thenable' is not assignable to type 'PromiseLike<any>'.
|
||||
Types of property 'then' are incompatible.
|
||||
Type '() => void' is not assignable to type '{ <TResult>(onfulfilled?: (value: any) => TResult | PromiseLike<TResult>, onrejected?: (reason: any) => TResult | PromiseLike<TResult>): PromiseLike<TResult>; <TResult>(onfulfilled?: (value: any) => TResult | PromiseLike<TResult>, onrejected?: (reason: any) => void): PromiseLike<TResult>; }'.
|
||||
Type 'void' is not assignable to type 'PromiseLike<any>'.
|
||||
tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration15_es6.ts(17,16): error TS1059: Return expression in async function does not have a valid callable 'then' member.
|
||||
tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration15_es6.ts(23,25): error TS1058: Operand for 'await' does not have a valid callable 'then' member.
|
||||
|
||||
|
||||
==== tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration15_es6.ts (7 errors) ====
|
||||
==== tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration15_es6.ts (8 errors) ====
|
||||
declare class Thenable { then(): void; }
|
||||
declare let a: any;
|
||||
declare let obj: { then: string; };
|
||||
declare let thenable: Thenable;
|
||||
async function fn1() { } // valid: Promise<void>
|
||||
async function fn2(): { } { } // error
|
||||
~~~
|
||||
!!! error TS1064: The return type of an async function or method must be the global Promise<T> type.
|
||||
~~~
|
||||
!!! error TS1055: Type '{}' is not a valid async function return type.
|
||||
async function fn3(): any { } // error
|
||||
~~~
|
||||
!!! error TS1064: The return type of an async function or method must be the global Promise<T> type.
|
||||
~~~
|
||||
!!! error TS1055: Type 'any' is not a valid async function return type.
|
||||
async function fn4(): number { } // error
|
||||
~~~~~~
|
||||
!!! error TS1064: The return type of an async function or method must be the global Promise<T> type.
|
||||
~~~
|
||||
!!! error TS1055: Type 'number' is not a valid async function return type.
|
||||
async function fn5(): PromiseLike<void> { } // error
|
||||
~~~~~~~~~~~~~~~~~
|
||||
!!! error TS1064: The return type of an async function or method must be the global Promise<T> type.
|
||||
~~~
|
||||
!!! error TS1055: Type 'PromiseLike' is not a valid async function return type.
|
||||
async function fn6(): Thenable { } // error
|
||||
~~~~~~~~
|
||||
!!! error TS1064: The return type of an async function or method must be the global Promise<T> type.
|
||||
~~~
|
||||
!!! error TS1055: Type 'typeof Thenable' is not a valid async function return type.
|
||||
~~~
|
||||
!!! error TS1055: Type 'typeof Thenable' is not a valid async function return type.
|
||||
!!! error TS1055: Type 'Thenable' is not assignable to type 'PromiseLike<any>'.
|
||||
!!! error TS1055: Types of property 'then' are incompatible.
|
||||
!!! error TS1055: Type '() => void' is not assignable to type '{ <TResult>(onfulfilled?: (value: any) => TResult | PromiseLike<TResult>, onrejected?: (reason: any) => TResult | PromiseLike<TResult>): PromiseLike<TResult>; <TResult>(onfulfilled?: (value: any) => TResult | PromiseLike<TResult>, onrejected?: (reason: any) => void): PromiseLike<TResult>; }'.
|
||||
!!! error TS1055: Type 'void' is not assignable to type 'PromiseLike<any>'.
|
||||
async function fn7() { return; } // valid: Promise<void>
|
||||
async function fn8() { return 1; } // valid: Promise<number>
|
||||
async function fn9() { return null; } // valid: Promise<any>
|
||||
|
||||
@@ -38,10 +38,10 @@ function fn4() {
|
||||
return __awaiter(this, void 0, void 0, function* () { });
|
||||
} // error
|
||||
function fn5() {
|
||||
return __awaiter(this, void 0, void 0, function* () { });
|
||||
return __awaiter(this, void 0, PromiseLike, function* () { });
|
||||
} // error
|
||||
function fn6() {
|
||||
return __awaiter(this, void 0, void 0, function* () { });
|
||||
return __awaiter(this, void 0, Thenable, function* () { });
|
||||
} // error
|
||||
function fn7() {
|
||||
return __awaiter(this, void 0, void 0, function* () { return; });
|
||||
|
||||
@@ -4,6 +4,6 @@ async function foo(): Promise<void> {
|
||||
|
||||
//// [asyncFunctionDeclaration1_es6.js]
|
||||
function foo() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
return __awaiter(this, void 0, Promise, function* () {
|
||||
});
|
||||
}
|
||||
|
||||
@@ -4,6 +4,6 @@ async function foo(a = await): Promise<void> {
|
||||
|
||||
//// [asyncFunctionDeclaration6_es6.js]
|
||||
function foo(a = yield ) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
return __awaiter(this, void 0, Promise, function* () {
|
||||
});
|
||||
}
|
||||
|
||||
@@ -7,10 +7,10 @@ async function bar(): Promise<void> {
|
||||
|
||||
//// [asyncFunctionDeclaration7_es6.js]
|
||||
function bar() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
return __awaiter(this, void 0, Promise, function* () {
|
||||
// 'await' here is an identifier, and not a yield expression.
|
||||
function foo(a = yield ) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
return __awaiter(this, void 0, Promise, function* () {
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@@ -5,7 +5,7 @@ async function foo(): Promise<void> {
|
||||
|
||||
//// [asyncFunctionDeclaration9_es6.js]
|
||||
function foo() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
return __awaiter(this, void 0, Promise, function* () {
|
||||
var v = { [yield ]: foo };
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
tests/cases/conformance/async/es6/test.ts(3,25): error TS1064: The return type of an async function or method must be the global Promise<T> type.
|
||||
|
||||
|
||||
==== tests/cases/conformance/async/es6/task.ts (0 errors) ====
|
||||
export class Task<T> extends Promise<T> { }
|
||||
|
||||
==== tests/cases/conformance/async/es6/test.ts (1 errors) ====
|
||||
import { Task } from "./task";
|
||||
class Test {
|
||||
async example<T>(): Task<T> { return; }
|
||||
~~~~~~~
|
||||
!!! error TS1064: The return type of an async function or method must be the global Promise<T> type.
|
||||
}
|
||||
@@ -24,8 +24,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
||||
step((generator = generator.apply(thisArg, _arguments)).next());
|
||||
});
|
||||
};
|
||||
const task_1 = require("./task");
|
||||
class Test {
|
||||
example() {
|
||||
return __awaiter(this, void 0, void 0, function* () { return; });
|
||||
return __awaiter(this, void 0, task_1.Task, function* () { return; });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
=== tests/cases/conformance/async/es6/task.ts ===
|
||||
export class Task<T> extends Promise<T> { }
|
||||
>Task : Symbol(Task, Decl(task.ts, 0, 0))
|
||||
>T : Symbol(T, Decl(task.ts, 0, 18))
|
||||
>Promise : Symbol(Promise, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
|
||||
>T : Symbol(T, Decl(task.ts, 0, 18))
|
||||
|
||||
=== tests/cases/conformance/async/es6/test.ts ===
|
||||
import { Task } from "./task";
|
||||
>Task : Symbol(Task, Decl(test.ts, 0, 8))
|
||||
|
||||
class Test {
|
||||
>Test : Symbol(Test, Decl(test.ts, 0, 30))
|
||||
|
||||
async example<T>(): Task<T> { return; }
|
||||
>example : Symbol(example, Decl(test.ts, 1, 12))
|
||||
>T : Symbol(T, Decl(test.ts, 2, 18))
|
||||
>Task : Symbol(Task, Decl(test.ts, 0, 8))
|
||||
>T : Symbol(T, Decl(test.ts, 2, 18))
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
=== tests/cases/conformance/async/es6/task.ts ===
|
||||
export class Task<T> extends Promise<T> { }
|
||||
>Task : Task<T>
|
||||
>T : T
|
||||
>Promise : Promise<T>
|
||||
>T : T
|
||||
|
||||
=== tests/cases/conformance/async/es6/test.ts ===
|
||||
import { Task } from "./task";
|
||||
>Task : typeof Task
|
||||
|
||||
class Test {
|
||||
>Test : Test
|
||||
|
||||
async example<T>(): Task<T> { return; }
|
||||
>example : <T>() => Task<T>
|
||||
>T : T
|
||||
>Task : Task<T>
|
||||
>T : T
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
tests/cases/conformance/async/es6/asyncQualifiedReturnType_es6.ts(6,21): error TS1064: The return type of an async function or method must be the global Promise<T> type.
|
||||
|
||||
|
||||
==== tests/cases/conformance/async/es6/asyncQualifiedReturnType_es6.ts (1 errors) ====
|
||||
namespace X {
|
||||
export class MyPromise<T> extends Promise<T> {
|
||||
}
|
||||
}
|
||||
|
||||
async function f(): X.MyPromise<void> {
|
||||
~~~~~~~~~~~~~~~~~
|
||||
!!! error TS1064: The return type of an async function or method must be the global Promise<T> type.
|
||||
}
|
||||
@@ -15,6 +15,6 @@ var X;
|
||||
X.MyPromise = MyPromise;
|
||||
})(X || (X = {}));
|
||||
function f() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
return __awaiter(this, void 0, X.MyPromise, function* () {
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
=== tests/cases/conformance/async/es6/asyncQualifiedReturnType_es6.ts ===
|
||||
namespace X {
|
||||
>X : Symbol(X, Decl(asyncQualifiedReturnType_es6.ts, 0, 0))
|
||||
|
||||
export class MyPromise<T> extends Promise<T> {
|
||||
>MyPromise : Symbol(MyPromise, Decl(asyncQualifiedReturnType_es6.ts, 0, 13))
|
||||
>T : Symbol(T, Decl(asyncQualifiedReturnType_es6.ts, 1, 27))
|
||||
>Promise : Symbol(Promise, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
|
||||
>T : Symbol(T, Decl(asyncQualifiedReturnType_es6.ts, 1, 27))
|
||||
}
|
||||
}
|
||||
|
||||
async function f(): X.MyPromise<void> {
|
||||
>f : Symbol(f, Decl(asyncQualifiedReturnType_es6.ts, 3, 1))
|
||||
>X : Symbol(X, Decl(asyncQualifiedReturnType_es6.ts, 0, 0))
|
||||
>MyPromise : Symbol(X.MyPromise, Decl(asyncQualifiedReturnType_es6.ts, 0, 13))
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
=== tests/cases/conformance/async/es6/asyncQualifiedReturnType_es6.ts ===
|
||||
namespace X {
|
||||
>X : typeof X
|
||||
|
||||
export class MyPromise<T> extends Promise<T> {
|
||||
>MyPromise : MyPromise<T>
|
||||
>T : T
|
||||
>Promise : Promise<T>
|
||||
>T : T
|
||||
}
|
||||
}
|
||||
|
||||
async function f(): X.MyPromise<void> {
|
||||
>f : () => X.MyPromise<void>
|
||||
>X : any
|
||||
>MyPromise : X.MyPromise<T>
|
||||
}
|
||||
@@ -9,7 +9,7 @@ async function func(): Promise<void> {
|
||||
|
||||
//// [awaitBinaryExpression1_es6.js]
|
||||
function func() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
return __awaiter(this, void 0, Promise, function* () {
|
||||
"before";
|
||||
var b = (yield p) || a;
|
||||
"after";
|
||||
|
||||
@@ -9,7 +9,7 @@ async function func(): Promise<void> {
|
||||
|
||||
//// [awaitBinaryExpression2_es6.js]
|
||||
function func() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
return __awaiter(this, void 0, Promise, function* () {
|
||||
"before";
|
||||
var b = (yield p) && a;
|
||||
"after";
|
||||
|
||||
@@ -9,7 +9,7 @@ async function func(): Promise<void> {
|
||||
|
||||
//// [awaitBinaryExpression3_es6.js]
|
||||
function func() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
return __awaiter(this, void 0, Promise, function* () {
|
||||
"before";
|
||||
var b = (yield p) + a;
|
||||
"after";
|
||||
|
||||
@@ -9,7 +9,7 @@ async function func(): Promise<void> {
|
||||
|
||||
//// [awaitBinaryExpression4_es6.js]
|
||||
function func() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
return __awaiter(this, void 0, Promise, function* () {
|
||||
"before";
|
||||
var b = yield p, a;
|
||||
"after";
|
||||
|
||||
@@ -10,7 +10,7 @@ async function func(): Promise<void> {
|
||||
|
||||
//// [awaitBinaryExpression5_es6.js]
|
||||
function func() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
return __awaiter(this, void 0, Promise, function* () {
|
||||
"before";
|
||||
var o;
|
||||
o.a = yield p;
|
||||
|
||||
@@ -13,7 +13,7 @@ async function func(): Promise<void> {
|
||||
|
||||
//// [awaitCallExpression1_es6.js]
|
||||
function func() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
return __awaiter(this, void 0, Promise, function* () {
|
||||
"before";
|
||||
var b = fn(a, a, a);
|
||||
"after";
|
||||
|
||||
@@ -13,7 +13,7 @@ async function func(): Promise<void> {
|
||||
|
||||
//// [awaitCallExpression2_es6.js]
|
||||
function func() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
return __awaiter(this, void 0, Promise, function* () {
|
||||
"before";
|
||||
var b = fn(yield p, a, a);
|
||||
"after";
|
||||
|
||||
@@ -13,7 +13,7 @@ async function func(): Promise<void> {
|
||||
|
||||
//// [awaitCallExpression3_es6.js]
|
||||
function func() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
return __awaiter(this, void 0, Promise, function* () {
|
||||
"before";
|
||||
var b = fn(a, yield p, a);
|
||||
"after";
|
||||
|
||||
@@ -13,7 +13,7 @@ async function func(): Promise<void> {
|
||||
|
||||
//// [awaitCallExpression4_es6.js]
|
||||
function func() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
return __awaiter(this, void 0, Promise, function* () {
|
||||
"before";
|
||||
var b = (yield pfn)(a, a, a);
|
||||
"after";
|
||||
|
||||
@@ -13,7 +13,7 @@ async function func(): Promise<void> {
|
||||
|
||||
//// [awaitCallExpression5_es6.js]
|
||||
function func() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
return __awaiter(this, void 0, Promise, function* () {
|
||||
"before";
|
||||
var b = o.fn(a, a, a);
|
||||
"after";
|
||||
|
||||
@@ -13,7 +13,7 @@ async function func(): Promise<void> {
|
||||
|
||||
//// [awaitCallExpression6_es6.js]
|
||||
function func() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
return __awaiter(this, void 0, Promise, function* () {
|
||||
"before";
|
||||
var b = o.fn(yield p, a, a);
|
||||
"after";
|
||||
|
||||
@@ -13,7 +13,7 @@ async function func(): Promise<void> {
|
||||
|
||||
//// [awaitCallExpression7_es6.js]
|
||||
function func() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
return __awaiter(this, void 0, Promise, function* () {
|
||||
"before";
|
||||
var b = o.fn(a, yield p, a);
|
||||
"after";
|
||||
|
||||
@@ -13,7 +13,7 @@ async function func(): Promise<void> {
|
||||
|
||||
//// [awaitCallExpression8_es6.js]
|
||||
function func() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
return __awaiter(this, void 0, Promise, function* () {
|
||||
"before";
|
||||
var b = (yield po).fn(a, a, a);
|
||||
"after";
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
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.
|
||||
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.
|
||||
|
||||
|
||||
==== tests/cases/conformance/async/es6/noCustomAsyncReturnType_es6.ts (2 errors) ====
|
||||
|
||||
interface Promise<T> extends PromiseLike<T> {}
|
||||
var Promise: PromiseConstructorLike;
|
||||
~~~~~~~
|
||||
!!! error TS2529: Duplicate identifier 'Promise'. Compiler reserves name 'Promise' in top level scope of a module containing async functions.
|
||||
|
||||
export async function f(): Promise<void> {
|
||||
~~~~~~~~~~~~~
|
||||
!!! error TS1064: The return type of an async function or method must be the global Promise<T> type.
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
//// [noCustomAsyncReturnType_es6.ts]
|
||||
|
||||
interface Promise<T> extends PromiseLike<T> {}
|
||||
var Promise: PromiseConstructorLike;
|
||||
|
||||
export async function f(): Promise<void> {
|
||||
}
|
||||
|
||||
|
||||
//// [noCustomAsyncReturnType_es6.js]
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator.throw(value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments)).next());
|
||||
});
|
||||
};
|
||||
var Promise;
|
||||
export function f() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
});
|
||||
}
|
||||
@@ -50,7 +50,7 @@ let x = function () {
|
||||
};
|
||||
// async function with which promised type is void - return can be omitted
|
||||
function f2() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
return __awaiter(this, void 0, Promise, function* () {
|
||||
});
|
||||
}
|
||||
function f3(x) {
|
||||
@@ -60,7 +60,7 @@ function f3(x) {
|
||||
});
|
||||
}
|
||||
function f4() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
return __awaiter(this, void 0, Promise, function* () {
|
||||
});
|
||||
}
|
||||
function voidFunc() {
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
// @target: ES6
|
||||
// @noCustomAsyncPromise: true
|
||||
|
||||
interface Promise<T> extends PromiseLike<T> {}
|
||||
var Promise: PromiseConstructorLike;
|
||||
|
||||
export async function f(): Promise<void> {
|
||||
}
|
||||
Reference in New Issue
Block a user