Skip to content

Commit 00e7d9c

Browse files
authored
Merge pull request #32334 from andrewbranch/no-missing-await-on-unary-arithmetic-expressions
Remove "Did you forget to use await" for unary arithmetic expressions
2 parents 34ffefb + f41c9b2 commit 00e7d9c

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

src/compiler/checker.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23713,9 +23713,9 @@ namespace ts {
2371323713
}
2371423714
}
2371523715

23716-
function checkArithmeticOperandType(operand: Node, type: Type, diagnostic: DiagnosticMessage): boolean {
23716+
function checkArithmeticOperandType(operand: Node, type: Type, diagnostic: DiagnosticMessage, isAwaitValid = false): boolean {
2371723717
if (!isTypeAssignableTo(type, numberOrBigIntType)) {
23718-
const awaitedType = getAwaitedType(type);
23718+
const awaitedType = isAwaitValid && getAwaitedTypeOfPromise(type);
2371923719
errorAndMaybeSuggestAwait(
2372023720
operand,
2372123721
!!awaitedType && isTypeAssignableTo(awaitedType, numberOrBigIntType),
@@ -24327,8 +24327,8 @@ namespace ts {
2432724327
}
2432824328
else {
2432924329
// otherwise just check each operand separately and report errors as normal
24330-
const leftOk = checkArithmeticOperandType(left, leftType, Diagnostics.The_left_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_bigint_or_an_enum_type);
24331-
const rightOk = checkArithmeticOperandType(right, rightType, Diagnostics.The_right_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_bigint_or_an_enum_type);
24330+
const leftOk = checkArithmeticOperandType(left, leftType, Diagnostics.The_left_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_bigint_or_an_enum_type, /*isAwaitValid*/ true);
24331+
const rightOk = checkArithmeticOperandType(right, rightType, Diagnostics.The_right_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_bigint_or_an_enum_type, /*isAwaitValid*/ true);
2433224332
let resultType: Type;
2433324333
// If both are any or unknown, allow operation; assume it will resolve to number
2433424334
if ((isTypeAssignableToKind(leftType, TypeFlags.AnyOrUnknown) && isTypeAssignableToKind(rightType, TypeFlags.AnyOrUnknown)) ||

tests/baselines/reference/operationsAvailableOnPromisedType.errors.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,9 @@ tests/cases/compiler/operationsAvailableOnPromisedType.ts(27,5): error TS2349: T
5151
b++;
5252
~
5353
!!! error TS2356: An arithmetic operand must be of type 'any', 'number', 'bigint' or an enum type.
54-
!!! related TS2773 tests/cases/compiler/operationsAvailableOnPromisedType.ts:15:5: Did you forget to use 'await'?
5554
--b;
5655
~
5756
!!! error TS2356: An arithmetic operand must be of type 'any', 'number', 'bigint' or an enum type.
58-
!!! related TS2773 tests/cases/compiler/operationsAvailableOnPromisedType.ts:16:7: Did you forget to use 'await'?
5957
a === b;
6058
~~~~~~~
6159
!!! error TS2367: This condition will always return 'false' since the types 'number' and 'Promise<number>' have no overlap.

0 commit comments

Comments
 (0)