Skip to content

Commit 9201ba2

Browse files
committed
Merge pull request #5429 from Microsoft/fixAsyncTypeAlias
Fix type check for async function with alias return type.
2 parents d28acec + fdac86f commit 9201ba2

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

src/compiler/checker.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5479,7 +5479,7 @@ namespace ts {
54795479
let targetType = getIndexTypeOfType(target, IndexKind.String);
54805480
if (targetType) {
54815481
if ((targetType.flags & TypeFlags.Any) && !(originalSource.flags & TypeFlags.Primitive)) {
5482-
// non-primitive assignment to any is always allowed, eg
5482+
// non-primitive assignment to any is always allowed, eg
54835483
// `var x: { [index: string]: any } = { property: 12 };`
54845484
return Ternary.True;
54855485
}
@@ -5509,7 +5509,7 @@ namespace ts {
55095509
let targetType = getIndexTypeOfType(target, IndexKind.Number);
55105510
if (targetType) {
55115511
if ((targetType.flags & TypeFlags.Any) && !(originalSource.flags & TypeFlags.Primitive)) {
5512-
// non-primitive assignment to any is always allowed, eg
5512+
// non-primitive assignment to any is always allowed, eg
55135513
// `var x: { [index: number]: any } = { property: 12 };`
55145514
return Ternary.True;
55155515
}
@@ -6586,9 +6586,9 @@ namespace ts {
65866586
return;
65876587
}
65886588

6589-
// 1. walk from the use site up to the declaration and check
6589+
// 1. walk from the use site up to the declaration and check
65906590
// if there is anything function like between declaration and use-site (is binding/class is captured in function).
6591-
// 2. walk from the declaration up to the boundary of lexical environment and check
6591+
// 2. walk from the declaration up to the boundary of lexical environment and check
65926592
// if there is an iteration statement in between declaration and boundary (is binding/class declared inside iteration statement)
65936593

65946594
let container: Node;
@@ -11639,9 +11639,12 @@ namespace ts {
1163911639
return unknownType;
1164011640
}
1164111641

11642-
let promiseConstructor = getMergedSymbol(promiseType.symbol);
11642+
let promiseConstructor = getNodeLinks(node.type).resolvedSymbol;
1164311643
if (!promiseConstructor || !symbolIsValue(promiseConstructor)) {
11644-
error(node, Diagnostics.Type_0_is_not_a_valid_async_function_return_type, typeToString(promiseType));
11644+
let typeName = promiseConstructor
11645+
? symbolToString(promiseConstructor)
11646+
: typeToString(promiseType);
11647+
error(node, Diagnostics.Type_0_is_not_a_valid_async_function_return_type, typeName);
1164511648
return unknownType;
1164611649
}
1164711650

tests/baselines/reference/asyncFunctionDeclaration15_es6.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration15_es6.ts(6,16): error TS1055: Type '{}' is not a valid async function return type.
22
tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration15_es6.ts(7,16): error TS1055: Type 'any' is not a valid async function return type.
33
tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration15_es6.ts(8,16): error TS1055: Type 'number' is not a valid async function return type.
4-
tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration15_es6.ts(9,16): error TS1055: Type 'PromiseLike<void>' is not a valid async function return type.
4+
tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration15_es6.ts(9,16): error TS1055: Type 'PromiseLike' is not a valid async function return type.
55
tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration15_es6.ts(10,16): error TS1055: Type 'typeof Thenable' is not a valid async function return type.
66
Type 'Thenable' is not assignable to type 'PromiseLike<any>'.
77
Types of property 'then' are incompatible.
@@ -28,7 +28,7 @@ tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration1
2828
!!! error TS1055: Type 'number' is not a valid async function return type.
2929
async function fn5(): PromiseLike<void> { } // error
3030
~~~
31-
!!! error TS1055: Type 'PromiseLike<void>' is not a valid async function return type.
31+
!!! error TS1055: Type 'PromiseLike' is not a valid async function return type.
3232
async function fn6(): Thenable { } // error
3333
~~~
3434
!!! error TS1055: Type 'typeof Thenable' is not a valid async function return type.

0 commit comments

Comments
 (0)