Skip to content

Commit 8ce193c

Browse files
committed
Improved undefined/null handling for relational operators
1 parent a1e16d2 commit 8ce193c

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/compiler/checker.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14585,7 +14585,6 @@ namespace ts {
1458514585
}
1458614586
// NOTE: do not raise error if right is unknown as related error was already reported
1458714587
if (!(isTypeAny(rightType) ||
14588-
rightType.flags & TypeFlags.Nullable ||
1458914588
getSignaturesOfType(rightType, SignatureKind.Call).length ||
1459014589
getSignaturesOfType(rightType, SignatureKind.Construct).length ||
1459114590
isTypeSubtypeOf(rightType, globalFunctionType))) {
@@ -14598,6 +14597,8 @@ namespace ts {
1459814597
if (leftType === silentNeverType || rightType === silentNeverType) {
1459914598
return silentNeverType;
1460014599
}
14600+
leftType = checkNonNullType(leftType, left);
14601+
rightType = checkNonNullType(rightType, right);
1460114602
// TypeScript 1.0 spec (April 2014): 4.15.5
1460214603
// The in operator requires the left operand to be of type Any, the String primitive type, or the Number primitive type,
1460314604
// and the right operand to be of type Any, an object type, or a type parameter type.
@@ -14952,8 +14953,8 @@ namespace ts {
1495214953
case SyntaxKind.LessThanEqualsToken:
1495314954
case SyntaxKind.GreaterThanEqualsToken:
1495414955
if (checkForDisallowedESSymbolOperand(operator)) {
14955-
leftType = getBaseTypeOfLiteralType(leftType);
14956-
rightType = getBaseTypeOfLiteralType(rightType);
14956+
leftType = getBaseTypeOfLiteralType(checkNonNullType(leftType, left));
14957+
rightType = getBaseTypeOfLiteralType(checkNonNullType(rightType, right));
1495714958
if (!isTypeComparableTo(leftType, rightType) && !isTypeComparableTo(rightType, leftType)) {
1495814959
reportOperatorError();
1495914960
}

0 commit comments

Comments
 (0)