Skip to content

Commit 94b37b1

Browse files
committed
Inline isThenableType
1 parent 56a360c commit 94b37b1

File tree

1 file changed

+2
-21
lines changed

1 file changed

+2
-21
lines changed

src/compiler/checker.ts

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16661,26 +16661,6 @@ namespace ts {
1666116661
return promisedType && getAwaitedType(promisedType, errorNode);
1666216662
}
1666316663

16664-
/**
16665-
* Determines whether a type has a callable 'then' method.
16666-
*/
16667-
function isThenableType(type: Type) {
16668-
//
16669-
// {
16670-
// then( // thenFunction
16671-
// ): any;
16672-
// }
16673-
//
16674-
16675-
const thenFunction = getTypeOfPropertyOfType(type, "then");
16676-
const thenSignatures = thenFunction ? getSignaturesOfType(thenFunction, SignatureKind.Call) : emptyArray;
16677-
if (thenSignatures.length > 0) {
16678-
return true;
16679-
}
16680-
16681-
return false;
16682-
}
16683-
1668416664
/**
1668516665
* Gets the "promised type" of a promise.
1668616666
* @param type The type of the promise.
@@ -16842,7 +16822,8 @@ namespace ts {
1684216822
// of a runtime problem. If the user wants to return this value from an async
1684316823
// function, they would need to wrap it in some other value. If they want it to
1684416824
// be treated as a promise, they can cast to <any>.
16845-
if (isThenableType(type)) {
16825+
const thenFunction = getTypeOfPropertyOfType(type, "then");
16826+
if (thenFunction && getSignaturesOfType(thenFunction, SignatureKind.Call).length > 0) {
1684616827
if (errorNode) {
1684716828
error(errorNode, Diagnostics.Type_used_as_operand_to_await_or_the_return_type_of_an_async_function_must_either_be_a_valid_promise_or_must_not_contain_a_callable_then_member);
1684816829
}

0 commit comments

Comments
 (0)