Skip to content

Commit 74498bb

Browse files
committed
Remove unnecessary widening, more PR feedback
1 parent f9999e9 commit 74498bb

File tree

3 files changed

+6
-10
lines changed

3 files changed

+6
-10
lines changed

src/compiler/checker.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16493,7 +16493,6 @@ namespace ts {
1649316493
// }
1649416494
//
1649516495

16496-
// TODO(rbuckton): Verify whether we need to call getApparentType. See checkNonThenableType in master
1649716496
const thenFunction = getTypeOfPropertyOfType(type, "then");
1649816497
const thenSignatures = thenFunction ? getSignaturesOfType(thenFunction, SignatureKind.Call) : emptyArray;
1649916498
if (thenSignatures.length > 0) {
@@ -16600,7 +16599,7 @@ namespace ts {
1660016599
if (type.id === promisedType.id || indexOf(awaitedTypeStack, promisedType.id) >= 0) {
1660116600
// Verify that we don't have a bad actor in the form of a promise whose
1660216601
// promised type is the same as the promise type, or a mutually recursive
16603-
// promise. If so, we returnundefined as we cannot guess the shape. If this
16602+
// promise. If so, we return undefined as we cannot guess the shape. If this
1660416603
// were the actual case in the JavaScript, this Promise would never resolve.
1660516604
//
1660616605
// An example of a bad actor with a singly-recursive promise type might
@@ -16664,15 +16663,14 @@ namespace ts {
1666416663
// of a runtime problem. If the user wants to return this value from an async
1666516664
// function, they would need to wrap it in some other value. If they want it to
1666616665
// be treated as a promise, they can cast to <any>.
16667-
const widenedType = getWidenedType(type);
16668-
if (isThenableType(widenedType)) {
16666+
if (isThenableType(type)) {
1666916667
if (errorNode) {
1667016668
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);
1667116669
}
1667216670
return undefined;
1667316671
}
1667416672

16675-
return typeAsAwaitable.awaitedTypeOfType = widenedType;
16673+
return typeAsAwaitable.awaitedTypeOfType = type;
1667616674
}
1667716675

1667816676
/**

src/compiler/comments.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,7 @@ namespace ts {
262262

263263
function forEachLeadingCommentToEmit(pos: number, cb: (commentPos: number, commentEnd: number, kind: SyntaxKind, hasTrailingNewLine: boolean, rangePos: number) => void) {
264264
// Emit the leading comments only if the container's pos doesn't match because the container should take care of emitting these comments
265-
if ((containerPos === -1 || pos !== containerPos) /* && !leadingCommentPositions[pos] */) {
266-
// leadingCommentPositions[pos] = true;
265+
if ((containerPos === -1 || pos !== containerPos)) {
267266
if (hasDetachedComments(pos)) {
268267
forEachLeadingCommentWithoutDetachedComments(cb);
269268
}
@@ -275,8 +274,7 @@ namespace ts {
275274

276275
function forEachTrailingCommentToEmit(end: number, cb: (commentPos: number, commentEnd: number, kind: SyntaxKind, hasTrailingNewLine: boolean) => void) {
277276
// Emit the trailing comments only if the container's end doesn't match because the container should take care of emitting these comments
278-
if ((containerEnd === -1 || (end !== containerEnd && end !== declarationListContainerEnd)) /*&& !trailingCommentPositions[end] */) {
279-
// trailingCommentPositions[end] = true;
277+
if ((containerEnd === -1 || (end !== containerEnd && end !== declarationListContainerEnd))) {
280278
forEachTrailingCommentRange(currentText, end, cb);
281279
}
282280
}

tests/baselines/reference/castOfAwait.types

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ async function f() {
1818
>0 : 0
1919

2020
await void <string> typeof <number> void await 0;
21-
>await void <string> typeof <number> void await 0 : any
21+
>await void <string> typeof <number> void await 0 : undefined
2222
>void <string> typeof <number> void await 0 : undefined
2323
><string> typeof <number> void await 0 : string
2424
>typeof <number> void await 0 : string

0 commit comments

Comments
 (0)