Skip to content

Commit 984956a

Browse files
authored
Only add unnecessary-await suggestion on await expressions (#32754)
1 parent 9971e8b commit 984956a

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

src/compiler/checker.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24037,7 +24037,11 @@ namespace ts {
2403724037
}
2403824038

2403924039
const operandType = checkExpression(node.expression);
24040-
return checkAwaitedType(operandType, node, Diagnostics.Type_of_await_operand_must_either_be_a_valid_promise_or_must_not_contain_a_callable_then_member);
24040+
const awaitedType = checkAwaitedType(operandType, node, Diagnostics.Type_of_await_operand_must_either_be_a_valid_promise_or_must_not_contain_a_callable_then_member);
24041+
if (awaitedType === operandType && awaitedType !== errorType && !(operandType.flags & TypeFlags.AnyOrUnknown)) {
24042+
addErrorOrSuggestion(/*isError*/ false, createDiagnosticForNode(node, Diagnostics.await_has_no_effect_on_the_type_of_this_expression));
24043+
}
24044+
return awaitedType;
2404124045
}
2404224046

2404324047
function checkPrefixUnaryExpression(node: PrefixUnaryExpression): Type {
@@ -26537,9 +26541,6 @@ namespace ts {
2653726541
*/
2653826542
function checkAwaitedType(type: Type, errorNode: Node, diagnosticMessage: DiagnosticMessage, arg0?: string | number): Type {
2653926543
const awaitedType = getAwaitedType(type, errorNode, diagnosticMessage, arg0);
26540-
if (awaitedType === type && !(type.flags & TypeFlags.AnyOrUnknown)) {
26541-
addErrorOrSuggestion(/*isError*/ false, createDiagnosticForNode(errorNode, Diagnostics.await_has_no_effect_on_the_type_of_this_expression));
26542-
}
2654326544
return awaitedType || errorType;
2654426545
}
2654526546

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
// @target: esnext
4+
////async function fn(): Promise<number> {
5+
//// return 0;
6+
////}
7+
8+
verify.getSuggestionDiagnostics([]);

0 commit comments

Comments
 (0)