Remove the rule that replaces a union of literal types with the base type when comparing equality to a type that isn't a union of literal types. (#27588)

type when comparing equality to a type that isn't a union of literal
types.

The rule is redundant because a primitive type is already directed-
comparable to a value of that primitive type, and it causes errors to be
missed when comparing a type parameter _constrained_ by a union of
literal types to another union of literal types.

The baseline changes look like improvements to me.

Fixes #26758.
This commit is contained in:
Matt McCutchen
2019-04-23 15:59:07 -04:00
committed by Ryan Cavanaugh
parent bd178746de
commit 6487d1ffe0
12 changed files with 110 additions and 24 deletions

View File

@@ -23320,12 +23320,6 @@ namespace ts {
case SyntaxKind.ExclamationEqualsToken:
case SyntaxKind.EqualsEqualsEqualsToken:
case SyntaxKind.ExclamationEqualsEqualsToken:
const leftIsLiteral = isLiteralType(leftType);
const rightIsLiteral = isLiteralType(rightType);
if (!leftIsLiteral || !rightIsLiteral) {
leftType = leftIsLiteral ? getBaseTypeOfLiteralType(leftType) : leftType;
rightType = rightIsLiteral ? getBaseTypeOfLiteralType(rightType) : rightType;
}
if (!isTypeEqualityComparableTo(leftType, rightType) && !isTypeEqualityComparableTo(rightType, leftType)) {
reportOperatorError();
}