@@ -7632,12 +7632,10 @@ namespace ts {
7632
7632
if (globalPromiseType !== emptyObjectType) {
7633
7633
// if the promised type is itself a promise, get the underlying type; otherwise, fallback to the promised type
7634
7634
promisedType = getAwaitedType(promisedType);
7635
- if (promisedType !== unknownType) {
7636
- return createTypeReference(<GenericType>globalPromiseType, [promisedType]);
7637
- }
7635
+ return createTypeReference(<GenericType>globalPromiseType, [promisedType]);
7638
7636
}
7639
7637
7640
- return undefined ;
7638
+ return emptyObjectType ;
7641
7639
}
7642
7640
7643
7641
function getReturnTypeFromBody(func: FunctionLikeDeclaration, contextualMapper?: TypeMapper): Type {
@@ -7678,7 +7676,7 @@ namespace ts {
7678
7676
if (isAsync) {
7679
7677
// For an async function, the return type will not be void, but rather a Promise for void.
7680
7678
let promiseType = createPromiseType(voidType);
7681
- if (! promiseType) {
7679
+ if (promiseType === emptyObjectType ) {
7682
7680
error(func, Diagnostics.An_async_function_or_method_must_have_a_valid_awaitable_return_type);
7683
7681
return unknownType;
7684
7682
}
@@ -7688,7 +7686,7 @@ namespace ts {
7688
7686
else {
7689
7687
return voidType;
7690
7688
}
7691
- }
7689
+ }
7692
7690
}
7693
7691
// When yield/return statements are contextually typed we allow the return type to be a union type.
7694
7692
// Otherwise we require the yield/return expressions to have a best common supertype.
@@ -7718,7 +7716,7 @@ namespace ts {
7718
7716
// Promise/A+ compatible implementation will always assimilate any foreign promise, so the
7719
7717
// return type of the body is awaited type of the body, wrapped in a native Promise<T> type.
7720
7718
let promiseType = createPromiseType(widenedType);
7721
- if (! promiseType) {
7719
+ if (promiseType === emptyObjectType ) {
7722
7720
error(func, Diagnostics.An_async_function_or_method_must_have_a_valid_awaitable_return_type);
7723
7721
return unknownType;
7724
7722
}
@@ -9556,7 +9554,7 @@ namespace ts {
9556
9554
let promisedType = getPromisedType(type);
9557
9555
if (promisedType === undefined) {
9558
9556
// The type was not a PromiseLike, so it could not be unwrapped any further.
9559
- // As long as the type does not have a known callable "then" property, then it is
9557
+ // As long as the type does not have a callable "then" property, then it is
9560
9558
// safe to return the type; otherwise, an error will have been reported in
9561
9559
// the call to checkNonThenableType and we will return unknownType.
9562
9560
//
@@ -9570,11 +9568,10 @@ namespace ts {
9570
9568
// of a runtime problem. If the user wants to return this value from an async
9571
9569
// function, they would need to wrap it in some other value. If they want it to
9572
9570
// be treated as a promise, they can cast to <any>.
9573
- if (checkNonThenableType(type, location, message)) {
9574
- break ;
9571
+ if (! checkNonThenableType(type, location, message)) {
9572
+ type = unknownType ;
9575
9573
}
9576
9574
9577
- type = unknownType;
9578
9575
break;
9579
9576
}
9580
9577
0 commit comments