Skip to content

Commit 894ba85

Browse files
committed
Improved undefined/null handling for unary operators
1 parent 6dcaac6 commit 894ba85

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/compiler/checker.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14483,6 +14483,7 @@ namespace ts {
1448314483
case SyntaxKind.PlusToken:
1448414484
case SyntaxKind.MinusToken:
1448514485
case SyntaxKind.TildeToken:
14486+
checkNonNullType(operandType, node.operand);
1448614487
if (maybeTypeOfKind(operandType, TypeFlags.ESSymbol)) {
1448714488
error(node.operand, Diagnostics.The_0_operator_cannot_be_applied_to_type_symbol, tokenToString(node.operator));
1448814489
}
@@ -14494,7 +14495,7 @@ namespace ts {
1449414495
booleanType;
1449514496
case SyntaxKind.PlusPlusToken:
1449614497
case SyntaxKind.MinusMinusToken:
14497-
const ok = checkArithmeticOperandType(node.operand, getNonNullableType(operandType),
14498+
const ok = checkArithmeticOperandType(node.operand, checkNonNullType(operandType, node.operand),
1449814499
Diagnostics.An_arithmetic_operand_must_be_of_type_any_number_or_an_enum_type);
1449914500
if (ok) {
1450014501
// run check only if former checks succeeded to avoid reporting cascading errors
@@ -14510,7 +14511,7 @@ namespace ts {
1451014511
if (operandType === silentNeverType) {
1451114512
return silentNeverType;
1451214513
}
14513-
const ok = checkArithmeticOperandType(node.operand, getNonNullableType(operandType),
14514+
const ok = checkArithmeticOperandType(node.operand, checkNonNullType(operandType, node.operand),
1451414515
Diagnostics.An_arithmetic_operand_must_be_of_type_any_number_or_an_enum_type);
1451514516
if (ok) {
1451614517
// run check only if former checks succeeded to avoid reporting cascading errors

0 commit comments

Comments
 (0)