Remove "Did you forget to use await" for unary arithmetic expressions

This commit is contained in:
Andrew Branch 2019-07-10 13:18:37 -07:00
parent 34ffefb922
commit ab9e583e45
No known key found for this signature in database
GPG Key ID: 22CCA4B120C427D2
2 changed files with 4 additions and 6 deletions

View File

@ -23713,9 +23713,9 @@ namespace ts {
}
}
function checkArithmeticOperandType(operand: Node, type: Type, diagnostic: DiagnosticMessage): boolean {
function checkArithmeticOperandType(operand: Node, type: Type, diagnostic: DiagnosticMessage, tryAwait = false): boolean {
if (!isTypeAssignableTo(type, numberOrBigIntType)) {
const awaitedType = getAwaitedType(type);
const awaitedType = tryAwait && getAwaitedTypeOfPromise(type);
errorAndMaybeSuggestAwait(
operand,
!!awaitedType && isTypeAssignableTo(awaitedType, numberOrBigIntType),
@ -24327,8 +24327,8 @@ namespace ts {
}
else {
// otherwise just check each operand separately and report errors as normal
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);
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);
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, /*tryAwait*/ true);
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, /*tryAwait*/ true);
let resultType: Type;
// If both are any or unknown, allow operation; assume it will resolve to number
if ((isTypeAssignableToKind(leftType, TypeFlags.AnyOrUnknown) && isTypeAssignableToKind(rightType, TypeFlags.AnyOrUnknown)) ||

View File

@ -51,11 +51,9 @@ tests/cases/compiler/operationsAvailableOnPromisedType.ts(27,5): error TS2349: T
b++;
~
!!! error TS2356: An arithmetic operand must be of type 'any', 'number', 'bigint' or an enum type.
!!! related TS2773 tests/cases/compiler/operationsAvailableOnPromisedType.ts:15:5: Did you forget to use 'await'?
--b;
~
!!! error TS2356: An arithmetic operand must be of type 'any', 'number', 'bigint' or an enum type.
!!! related TS2773 tests/cases/compiler/operationsAvailableOnPromisedType.ts:16:7: Did you forget to use 'await'?
a === b;
~~~~~~~
!!! error TS2367: This condition will always return 'false' since the types 'number' and 'Promise<number>' have no overlap.