mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-21 08:25:43 -05:00
Equality comparisons for null/undefined in strict null checking mode
This commit is contained in:
@@ -12053,6 +12053,10 @@ namespace ts {
|
||||
return sourceType;
|
||||
}
|
||||
|
||||
function isTypeEqualityComparableTo(source: Type, target: Type) {
|
||||
return (target.flags & TypeFlags.Nullable) !== 0 || isTypeComparableTo(source, target);
|
||||
}
|
||||
|
||||
function checkBinaryExpression(node: BinaryExpression, contextualMapper?: TypeMapper) {
|
||||
return checkBinaryLikeExpression(node.left, node.operatorToken, node.right, contextualMapper, node);
|
||||
}
|
||||
@@ -12166,15 +12170,17 @@ namespace ts {
|
||||
case SyntaxKind.GreaterThanToken:
|
||||
case SyntaxKind.LessThanEqualsToken:
|
||||
case SyntaxKind.GreaterThanEqualsToken:
|
||||
if (!checkForDisallowedESSymbolOperand(operator)) {
|
||||
return booleanType;
|
||||
if (checkForDisallowedESSymbolOperand(operator)) {
|
||||
if (!isTypeComparableTo(leftType, rightType) && !isTypeComparableTo(rightType, leftType)) {
|
||||
reportOperatorError();
|
||||
}
|
||||
}
|
||||
// Fall through
|
||||
return booleanType;
|
||||
case SyntaxKind.EqualsEqualsToken:
|
||||
case SyntaxKind.ExclamationEqualsToken:
|
||||
case SyntaxKind.EqualsEqualsEqualsToken:
|
||||
case SyntaxKind.ExclamationEqualsEqualsToken:
|
||||
if (!isTypeComparableTo(leftType, rightType) && !isTypeComparableTo(rightType, leftType)) {
|
||||
if (!isTypeEqualityComparableTo(leftType, rightType) && !isTypeEqualityComparableTo(rightType, leftType)) {
|
||||
reportOperatorError();
|
||||
}
|
||||
return booleanType;
|
||||
|
||||
Reference in New Issue
Block a user