Skip to content

Commit 02f6622

Browse files
committed
Changed createPromiseType to return emptyObjectType
1 parent b00a957 commit 02f6622

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

src/compiler/checker.ts

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7632,12 +7632,10 @@ namespace ts {
76327632
if (globalPromiseType !== emptyObjectType) {
76337633
// if the promised type is itself a promise, get the underlying type; otherwise, fallback to the promised type
76347634
promisedType = getAwaitedType(promisedType);
7635-
if (promisedType !== unknownType) {
7636-
return createTypeReference(<GenericType>globalPromiseType, [promisedType]);
7637-
}
7635+
return createTypeReference(<GenericType>globalPromiseType, [promisedType]);
76387636
}
76397637

7640-
return undefined;
7638+
return emptyObjectType;
76417639
}
76427640

76437641
function getReturnTypeFromBody(func: FunctionLikeDeclaration, contextualMapper?: TypeMapper): Type {
@@ -7678,7 +7676,7 @@ namespace ts {
76787676
if (isAsync) {
76797677
// For an async function, the return type will not be void, but rather a Promise for void.
76807678
let promiseType = createPromiseType(voidType);
7681-
if (!promiseType) {
7679+
if (promiseType === emptyObjectType) {
76827680
error(func, Diagnostics.An_async_function_or_method_must_have_a_valid_awaitable_return_type);
76837681
return unknownType;
76847682
}
@@ -7688,7 +7686,7 @@ namespace ts {
76887686
else {
76897687
return voidType;
76907688
}
7691-
}
7689+
}
76927690
}
76937691
// When yield/return statements are contextually typed we allow the return type to be a union type.
76947692
// Otherwise we require the yield/return expressions to have a best common supertype.
@@ -7718,7 +7716,7 @@ namespace ts {
77187716
// Promise/A+ compatible implementation will always assimilate any foreign promise, so the
77197717
// return type of the body is awaited type of the body, wrapped in a native Promise<T> type.
77207718
let promiseType = createPromiseType(widenedType);
7721-
if (!promiseType) {
7719+
if (promiseType === emptyObjectType) {
77227720
error(func, Diagnostics.An_async_function_or_method_must_have_a_valid_awaitable_return_type);
77237721
return unknownType;
77247722
}
@@ -9556,7 +9554,7 @@ namespace ts {
95569554
let promisedType = getPromisedType(type);
95579555
if (promisedType === undefined) {
95589556
// 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
95609558
// safe to return the type; otherwise, an error will have been reported in
95619559
// the call to checkNonThenableType and we will return unknownType.
95629560
//
@@ -9570,11 +9568,10 @@ namespace ts {
95709568
// of a runtime problem. If the user wants to return this value from an async
95719569
// function, they would need to wrap it in some other value. If they want it to
95729570
// 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;
95759573
}
95769574

9577-
type = unknownType;
95789575
break;
95799576
}
95809577

0 commit comments

Comments
 (0)