diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 5200b9b4cafde..1427ee3a1fc86 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -22983,6 +22983,17 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { return getCachedType(key) ?? setCachedType(key, mapType(type, getBaseTypeOfLiteralType)); } + // This like getBaseTypeOfLiteralType, but instead treats enum literals as strings/numbers instead + // of returning their enum base type (which depends on the types of other literals in the enum). + function getBaseTypeOfLiteralTypeForComparison(type: Type): Type { + return type.flags & (TypeFlags.StringLiteral | TypeFlags.TemplateLiteral | TypeFlags.StringMapping) ? stringType : + type.flags & (TypeFlags.NumberLiteral | TypeFlags.Enum) ? numberType : + type.flags & TypeFlags.BigIntLiteral ? bigintType : + type.flags & TypeFlags.BooleanLiteral ? booleanType : + type.flags & TypeFlags.Union ? mapType(type, getBaseTypeOfLiteralTypeForComparison) : + type; + } + function getWidenedLiteralType(type: Type): Type { return type.flags & TypeFlags.EnumLiteral && isFreshLiteralType(type) ? getBaseTypeOfEnumLiteralType(type as LiteralType) : type.flags & TypeFlags.StringLiteral && isFreshLiteralType(type) ? stringType : @@ -36423,8 +36434,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { case SyntaxKind.LessThanEqualsToken: case SyntaxKind.GreaterThanEqualsToken: if (checkForDisallowedESSymbolOperand(operator)) { - leftType = getBaseTypeOfLiteralType(checkNonNullType(leftType, left)); - rightType = getBaseTypeOfLiteralType(checkNonNullType(rightType, right)); + leftType = getBaseTypeOfLiteralTypeForComparison(checkNonNullType(leftType, left)); + rightType = getBaseTypeOfLiteralTypeForComparison(checkNonNullType(rightType, right)); reportOperatorErrorUnless((left, right) => { if (isTypeAny(left) || isTypeAny(right)) { return true; diff --git a/tests/baselines/reference/comparisonOperatorWithNoRelationshipPrimitiveType.errors.txt b/tests/baselines/reference/comparisonOperatorWithNoRelationshipPrimitiveType.errors.txt index a3565efb99e13..df66c774218c7 100644 --- a/tests/baselines/reference/comparisonOperatorWithNoRelationshipPrimitiveType.errors.txt +++ b/tests/baselines/reference/comparisonOperatorWithNoRelationshipPrimitiveType.errors.txt @@ -4,72 +4,72 @@ tests/cases/conformance/expressions/binaryOperators/comparisonOperator/compariso tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipPrimitiveType.ts(15,12): error TS2365: Operator '<' cannot be applied to types 'boolean' and 'number'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipPrimitiveType.ts(16,12): error TS2365: Operator '<' cannot be applied to types 'boolean' and 'string'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipPrimitiveType.ts(17,12): error TS2365: Operator '<' cannot be applied to types 'boolean' and 'void'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipPrimitiveType.ts(18,12): error TS2365: Operator '<' cannot be applied to types 'boolean' and 'E'. +tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipPrimitiveType.ts(18,12): error TS2365: Operator '<' cannot be applied to types 'boolean' and 'number'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipPrimitiveType.ts(20,12): error TS2365: Operator '<' cannot be applied to types 'string' and 'number'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipPrimitiveType.ts(21,12): error TS2365: Operator '<' cannot be applied to types 'string' and 'boolean'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipPrimitiveType.ts(22,12): error TS2365: Operator '<' cannot be applied to types 'string' and 'void'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipPrimitiveType.ts(23,12): error TS2365: Operator '<' cannot be applied to types 'string' and 'E'. +tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipPrimitiveType.ts(23,12): error TS2365: Operator '<' cannot be applied to types 'string' and 'number'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipPrimitiveType.ts(25,12): error TS2365: Operator '<' cannot be applied to types 'void' and 'number'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipPrimitiveType.ts(26,12): error TS2365: Operator '<' cannot be applied to types 'void' and 'boolean'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipPrimitiveType.ts(27,12): error TS2365: Operator '<' cannot be applied to types 'void' and 'string'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipPrimitiveType.ts(28,12): error TS2365: Operator '<' cannot be applied to types 'void' and 'E'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipPrimitiveType.ts(31,12): error TS2365: Operator '<' cannot be applied to types 'E' and 'boolean'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipPrimitiveType.ts(32,12): error TS2365: Operator '<' cannot be applied to types 'E' and 'string'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipPrimitiveType.ts(33,12): error TS2365: Operator '<' cannot be applied to types 'E' and 'void'. +tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipPrimitiveType.ts(28,12): error TS2365: Operator '<' cannot be applied to types 'void' and 'number'. +tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipPrimitiveType.ts(31,12): error TS2365: Operator '<' cannot be applied to types 'number' and 'boolean'. +tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipPrimitiveType.ts(32,12): error TS2365: Operator '<' cannot be applied to types 'number' and 'string'. +tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipPrimitiveType.ts(33,12): error TS2365: Operator '<' cannot be applied to types 'number' and 'void'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipPrimitiveType.ts(36,12): error TS2365: Operator '>' cannot be applied to types 'number' and 'boolean'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipPrimitiveType.ts(37,12): error TS2365: Operator '>' cannot be applied to types 'number' and 'string'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipPrimitiveType.ts(38,12): error TS2365: Operator '>' cannot be applied to types 'number' and 'void'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipPrimitiveType.ts(41,12): error TS2365: Operator '>' cannot be applied to types 'boolean' and 'number'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipPrimitiveType.ts(42,12): error TS2365: Operator '>' cannot be applied to types 'boolean' and 'string'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipPrimitiveType.ts(43,12): error TS2365: Operator '>' cannot be applied to types 'boolean' and 'void'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipPrimitiveType.ts(44,12): error TS2365: Operator '>' cannot be applied to types 'boolean' and 'E'. +tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipPrimitiveType.ts(44,12): error TS2365: Operator '>' cannot be applied to types 'boolean' and 'number'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipPrimitiveType.ts(46,12): error TS2365: Operator '>' cannot be applied to types 'string' and 'number'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipPrimitiveType.ts(47,12): error TS2365: Operator '>' cannot be applied to types 'string' and 'boolean'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipPrimitiveType.ts(48,12): error TS2365: Operator '>' cannot be applied to types 'string' and 'void'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipPrimitiveType.ts(49,12): error TS2365: Operator '>' cannot be applied to types 'string' and 'E'. +tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipPrimitiveType.ts(49,12): error TS2365: Operator '>' cannot be applied to types 'string' and 'number'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipPrimitiveType.ts(51,12): error TS2365: Operator '>' cannot be applied to types 'void' and 'number'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipPrimitiveType.ts(52,12): error TS2365: Operator '>' cannot be applied to types 'void' and 'boolean'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipPrimitiveType.ts(53,12): error TS2365: Operator '>' cannot be applied to types 'void' and 'string'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipPrimitiveType.ts(54,12): error TS2365: Operator '>' cannot be applied to types 'void' and 'E'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipPrimitiveType.ts(57,12): error TS2365: Operator '>' cannot be applied to types 'E' and 'boolean'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipPrimitiveType.ts(58,12): error TS2365: Operator '>' cannot be applied to types 'E' and 'string'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipPrimitiveType.ts(59,12): error TS2365: Operator '>' cannot be applied to types 'E' and 'void'. +tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipPrimitiveType.ts(54,12): error TS2365: Operator '>' cannot be applied to types 'void' and 'number'. +tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipPrimitiveType.ts(57,12): error TS2365: Operator '>' cannot be applied to types 'number' and 'boolean'. +tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipPrimitiveType.ts(58,12): error TS2365: Operator '>' cannot be applied to types 'number' and 'string'. +tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipPrimitiveType.ts(59,12): error TS2365: Operator '>' cannot be applied to types 'number' and 'void'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipPrimitiveType.ts(62,12): error TS2365: Operator '<=' cannot be applied to types 'number' and 'boolean'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipPrimitiveType.ts(63,12): error TS2365: Operator '<=' cannot be applied to types 'number' and 'string'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipPrimitiveType.ts(64,12): error TS2365: Operator '<=' cannot be applied to types 'number' and 'void'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipPrimitiveType.ts(67,12): error TS2365: Operator '<=' cannot be applied to types 'boolean' and 'number'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipPrimitiveType.ts(68,12): error TS2365: Operator '<=' cannot be applied to types 'boolean' and 'string'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipPrimitiveType.ts(69,12): error TS2365: Operator '<=' cannot be applied to types 'boolean' and 'void'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipPrimitiveType.ts(70,12): error TS2365: Operator '<=' cannot be applied to types 'boolean' and 'E'. +tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipPrimitiveType.ts(70,12): error TS2365: Operator '<=' cannot be applied to types 'boolean' and 'number'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipPrimitiveType.ts(72,12): error TS2365: Operator '<=' cannot be applied to types 'string' and 'number'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipPrimitiveType.ts(73,12): error TS2365: Operator '<=' cannot be applied to types 'string' and 'boolean'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipPrimitiveType.ts(74,12): error TS2365: Operator '<=' cannot be applied to types 'string' and 'void'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipPrimitiveType.ts(75,12): error TS2365: Operator '<=' cannot be applied to types 'string' and 'E'. +tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipPrimitiveType.ts(75,12): error TS2365: Operator '<=' cannot be applied to types 'string' and 'number'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipPrimitiveType.ts(77,12): error TS2365: Operator '<=' cannot be applied to types 'void' and 'number'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipPrimitiveType.ts(78,12): error TS2365: Operator '<=' cannot be applied to types 'void' and 'boolean'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipPrimitiveType.ts(79,12): error TS2365: Operator '<=' cannot be applied to types 'void' and 'string'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipPrimitiveType.ts(80,12): error TS2365: Operator '<=' cannot be applied to types 'void' and 'E'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipPrimitiveType.ts(83,12): error TS2365: Operator '<=' cannot be applied to types 'E' and 'boolean'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipPrimitiveType.ts(84,12): error TS2365: Operator '<=' cannot be applied to types 'E' and 'string'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipPrimitiveType.ts(85,12): error TS2365: Operator '<=' cannot be applied to types 'E' and 'void'. +tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipPrimitiveType.ts(80,12): error TS2365: Operator '<=' cannot be applied to types 'void' and 'number'. +tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipPrimitiveType.ts(83,12): error TS2365: Operator '<=' cannot be applied to types 'number' and 'boolean'. +tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipPrimitiveType.ts(84,12): error TS2365: Operator '<=' cannot be applied to types 'number' and 'string'. +tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipPrimitiveType.ts(85,12): error TS2365: Operator '<=' cannot be applied to types 'number' and 'void'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipPrimitiveType.ts(88,12): error TS2365: Operator '>=' cannot be applied to types 'number' and 'boolean'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipPrimitiveType.ts(89,12): error TS2365: Operator '>=' cannot be applied to types 'number' and 'string'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipPrimitiveType.ts(90,12): error TS2365: Operator '>=' cannot be applied to types 'number' and 'void'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipPrimitiveType.ts(93,12): error TS2365: Operator '>=' cannot be applied to types 'boolean' and 'number'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipPrimitiveType.ts(94,12): error TS2365: Operator '>=' cannot be applied to types 'boolean' and 'string'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipPrimitiveType.ts(95,12): error TS2365: Operator '>=' cannot be applied to types 'boolean' and 'void'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipPrimitiveType.ts(96,12): error TS2365: Operator '>=' cannot be applied to types 'boolean' and 'E'. +tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipPrimitiveType.ts(96,12): error TS2365: Operator '>=' cannot be applied to types 'boolean' and 'number'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipPrimitiveType.ts(98,12): error TS2365: Operator '>=' cannot be applied to types 'string' and 'number'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipPrimitiveType.ts(99,12): error TS2365: Operator '>=' cannot be applied to types 'string' and 'boolean'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipPrimitiveType.ts(100,12): error TS2365: Operator '>=' cannot be applied to types 'string' and 'void'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipPrimitiveType.ts(101,12): error TS2365: Operator '>=' cannot be applied to types 'string' and 'E'. +tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipPrimitiveType.ts(101,12): error TS2365: Operator '>=' cannot be applied to types 'string' and 'number'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipPrimitiveType.ts(103,12): error TS2365: Operator '>=' cannot be applied to types 'void' and 'number'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipPrimitiveType.ts(104,12): error TS2365: Operator '>=' cannot be applied to types 'void' and 'boolean'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipPrimitiveType.ts(105,12): error TS2365: Operator '>=' cannot be applied to types 'void' and 'string'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipPrimitiveType.ts(106,12): error TS2365: Operator '>=' cannot be applied to types 'void' and 'E'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipPrimitiveType.ts(109,12): error TS2365: Operator '>=' cannot be applied to types 'E' and 'boolean'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipPrimitiveType.ts(110,12): error TS2365: Operator '>=' cannot be applied to types 'E' and 'string'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipPrimitiveType.ts(111,12): error TS2365: Operator '>=' cannot be applied to types 'E' and 'void'. +tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipPrimitiveType.ts(106,12): error TS2365: Operator '>=' cannot be applied to types 'void' and 'number'. +tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipPrimitiveType.ts(109,12): error TS2365: Operator '>=' cannot be applied to types 'number' and 'boolean'. +tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipPrimitiveType.ts(110,12): error TS2365: Operator '>=' cannot be applied to types 'number' and 'string'. +tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipPrimitiveType.ts(111,12): error TS2365: Operator '>=' cannot be applied to types 'number' and 'void'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipPrimitiveType.ts(114,12): error TS2367: This comparison appears to be unintentional because the types 'number' and 'boolean' have no overlap. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipPrimitiveType.ts(115,12): error TS2367: This comparison appears to be unintentional because the types 'number' and 'string' have no overlap. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipPrimitiveType.ts(116,12): error TS2367: This comparison appears to be unintentional because the types 'number' and 'void' have no overlap. @@ -176,7 +176,7 @@ tests/cases/conformance/expressions/binaryOperators/comparisonOperator/compariso !!! error TS2365: Operator '<' cannot be applied to types 'boolean' and 'void'. var r1b1 = b < e; ~~~~~ -!!! error TS2365: Operator '<' cannot be applied to types 'boolean' and 'E'. +!!! error TS2365: Operator '<' cannot be applied to types 'boolean' and 'number'. var r1c1 = c < a; ~~~~~ @@ -189,7 +189,7 @@ tests/cases/conformance/expressions/binaryOperators/comparisonOperator/compariso !!! error TS2365: Operator '<' cannot be applied to types 'string' and 'void'. var r1c1 = c < e; ~~~~~ -!!! error TS2365: Operator '<' cannot be applied to types 'string' and 'E'. +!!! error TS2365: Operator '<' cannot be applied to types 'string' and 'number'. var r1d1 = d < a; ~~~~~ @@ -202,18 +202,18 @@ tests/cases/conformance/expressions/binaryOperators/comparisonOperator/compariso !!! error TS2365: Operator '<' cannot be applied to types 'void' and 'string'. var r1d1 = d < e; ~~~~~ -!!! error TS2365: Operator '<' cannot be applied to types 'void' and 'E'. +!!! error TS2365: Operator '<' cannot be applied to types 'void' and 'number'. var r1e1 = e < a; // no error, expected var r1e1 = e < b; ~~~~~ -!!! error TS2365: Operator '<' cannot be applied to types 'E' and 'boolean'. +!!! error TS2365: Operator '<' cannot be applied to types 'number' and 'boolean'. var r1e1 = e < c; ~~~~~ -!!! error TS2365: Operator '<' cannot be applied to types 'E' and 'string'. +!!! error TS2365: Operator '<' cannot be applied to types 'number' and 'string'. var r1e1 = e < d; ~~~~~ -!!! error TS2365: Operator '<' cannot be applied to types 'E' and 'void'. +!!! error TS2365: Operator '<' cannot be applied to types 'number' and 'void'. // operator > var r2a1 = a > b; @@ -238,7 +238,7 @@ tests/cases/conformance/expressions/binaryOperators/comparisonOperator/compariso !!! error TS2365: Operator '>' cannot be applied to types 'boolean' and 'void'. var r2b1 = b > e; ~~~~~ -!!! error TS2365: Operator '>' cannot be applied to types 'boolean' and 'E'. +!!! error TS2365: Operator '>' cannot be applied to types 'boolean' and 'number'. var r2c1 = c > a; ~~~~~ @@ -251,7 +251,7 @@ tests/cases/conformance/expressions/binaryOperators/comparisonOperator/compariso !!! error TS2365: Operator '>' cannot be applied to types 'string' and 'void'. var r2c1 = c > e; ~~~~~ -!!! error TS2365: Operator '>' cannot be applied to types 'string' and 'E'. +!!! error TS2365: Operator '>' cannot be applied to types 'string' and 'number'. var r2d1 = d > a; ~~~~~ @@ -264,18 +264,18 @@ tests/cases/conformance/expressions/binaryOperators/comparisonOperator/compariso !!! error TS2365: Operator '>' cannot be applied to types 'void' and 'string'. var r2d1 = d > e; ~~~~~ -!!! error TS2365: Operator '>' cannot be applied to types 'void' and 'E'. +!!! error TS2365: Operator '>' cannot be applied to types 'void' and 'number'. var r2e1 = e > a; // no error, expected var r2e1 = e > b; ~~~~~ -!!! error TS2365: Operator '>' cannot be applied to types 'E' and 'boolean'. +!!! error TS2365: Operator '>' cannot be applied to types 'number' and 'boolean'. var r2e1 = e > c; ~~~~~ -!!! error TS2365: Operator '>' cannot be applied to types 'E' and 'string'. +!!! error TS2365: Operator '>' cannot be applied to types 'number' and 'string'. var r2e1 = e > d; ~~~~~ -!!! error TS2365: Operator '>' cannot be applied to types 'E' and 'void'. +!!! error TS2365: Operator '>' cannot be applied to types 'number' and 'void'. // operator <= var r3a1 = a <= b; @@ -300,7 +300,7 @@ tests/cases/conformance/expressions/binaryOperators/comparisonOperator/compariso !!! error TS2365: Operator '<=' cannot be applied to types 'boolean' and 'void'. var r3b1 = b <= e; ~~~~~~ -!!! error TS2365: Operator '<=' cannot be applied to types 'boolean' and 'E'. +!!! error TS2365: Operator '<=' cannot be applied to types 'boolean' and 'number'. var r3c1 = c <= a; ~~~~~~ @@ -313,7 +313,7 @@ tests/cases/conformance/expressions/binaryOperators/comparisonOperator/compariso !!! error TS2365: Operator '<=' cannot be applied to types 'string' and 'void'. var r3c1 = c <= e; ~~~~~~ -!!! error TS2365: Operator '<=' cannot be applied to types 'string' and 'E'. +!!! error TS2365: Operator '<=' cannot be applied to types 'string' and 'number'. var r3d1 = d <= a; ~~~~~~ @@ -326,18 +326,18 @@ tests/cases/conformance/expressions/binaryOperators/comparisonOperator/compariso !!! error TS2365: Operator '<=' cannot be applied to types 'void' and 'string'. var r3d1 = d <= e; ~~~~~~ -!!! error TS2365: Operator '<=' cannot be applied to types 'void' and 'E'. +!!! error TS2365: Operator '<=' cannot be applied to types 'void' and 'number'. var r3e1 = e <= a; // no error, expected var r3e1 = e <= b; ~~~~~~ -!!! error TS2365: Operator '<=' cannot be applied to types 'E' and 'boolean'. +!!! error TS2365: Operator '<=' cannot be applied to types 'number' and 'boolean'. var r3e1 = e <= c; ~~~~~~ -!!! error TS2365: Operator '<=' cannot be applied to types 'E' and 'string'. +!!! error TS2365: Operator '<=' cannot be applied to types 'number' and 'string'. var r3e1 = e <= d; ~~~~~~ -!!! error TS2365: Operator '<=' cannot be applied to types 'E' and 'void'. +!!! error TS2365: Operator '<=' cannot be applied to types 'number' and 'void'. // operator >= var r4a1 = a >= b; @@ -362,7 +362,7 @@ tests/cases/conformance/expressions/binaryOperators/comparisonOperator/compariso !!! error TS2365: Operator '>=' cannot be applied to types 'boolean' and 'void'. var r4b1 = b >= e; ~~~~~~ -!!! error TS2365: Operator '>=' cannot be applied to types 'boolean' and 'E'. +!!! error TS2365: Operator '>=' cannot be applied to types 'boolean' and 'number'. var r4c1 = c >= a; ~~~~~~ @@ -375,7 +375,7 @@ tests/cases/conformance/expressions/binaryOperators/comparisonOperator/compariso !!! error TS2365: Operator '>=' cannot be applied to types 'string' and 'void'. var r4c1 = c >= e; ~~~~~~ -!!! error TS2365: Operator '>=' cannot be applied to types 'string' and 'E'. +!!! error TS2365: Operator '>=' cannot be applied to types 'string' and 'number'. var r4d1 = d >= a; ~~~~~~ @@ -388,18 +388,18 @@ tests/cases/conformance/expressions/binaryOperators/comparisonOperator/compariso !!! error TS2365: Operator '>=' cannot be applied to types 'void' and 'string'. var r4d1 = d >= e; ~~~~~~ -!!! error TS2365: Operator '>=' cannot be applied to types 'void' and 'E'. +!!! error TS2365: Operator '>=' cannot be applied to types 'void' and 'number'. var r4e1 = e >= a; // no error, expected var r4e1 = e >= b; ~~~~~~ -!!! error TS2365: Operator '>=' cannot be applied to types 'E' and 'boolean'. +!!! error TS2365: Operator '>=' cannot be applied to types 'number' and 'boolean'. var r4e1 = e >= c; ~~~~~~ -!!! error TS2365: Operator '>=' cannot be applied to types 'E' and 'string'. +!!! error TS2365: Operator '>=' cannot be applied to types 'number' and 'string'. var r4e1 = e >= d; ~~~~~~ -!!! error TS2365: Operator '>=' cannot be applied to types 'E' and 'void'. +!!! error TS2365: Operator '>=' cannot be applied to types 'number' and 'void'. // operator == var r5a1 = a == b; diff --git a/tests/baselines/reference/comparisonOperatorWithNoRelationshipTypeParameter.errors.txt b/tests/baselines/reference/comparisonOperatorWithNoRelationshipTypeParameter.errors.txt index de8a8ac3ce14c..165403a7c2ea2 100644 --- a/tests/baselines/reference/comparisonOperatorWithNoRelationshipTypeParameter.errors.txt +++ b/tests/baselines/reference/comparisonOperatorWithNoRelationshipTypeParameter.errors.txt @@ -7,37 +7,37 @@ tests/cases/conformance/expressions/binaryOperators/comparisonOperator/compariso tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipTypeParameter.ts(18,14): error TS2367: This comparison appears to be unintentional because the types 'T' and 'U' have no overlap. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipTypeParameter.ts(19,14): error TS2367: This comparison appears to be unintentional because the types 'T' and 'U' have no overlap. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipTypeParameter.ts(23,16): error TS2365: Operator '<' cannot be applied to types 'T' and 'number'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipTypeParameter.ts(26,16): error TS2365: Operator '<' cannot be applied to types 'T' and 'E'. +tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipTypeParameter.ts(26,16): error TS2365: Operator '<' cannot be applied to types 'T' and 'number'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipTypeParameter.ts(31,16): error TS2365: Operator '<' cannot be applied to types 'number' and 'T'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipTypeParameter.ts(34,16): error TS2365: Operator '<' cannot be applied to types 'E' and 'T'. +tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipTypeParameter.ts(34,16): error TS2365: Operator '<' cannot be applied to types 'number' and 'T'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipTypeParameter.ts(40,16): error TS2365: Operator '<' cannot be applied to types 'T' and 'number'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipTypeParameter.ts(43,16): error TS2365: Operator '<' cannot be applied to types 'T' and 'E'. +tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipTypeParameter.ts(43,16): error TS2365: Operator '<' cannot be applied to types 'T' and 'number'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipTypeParameter.ts(48,16): error TS2365: Operator '<' cannot be applied to types 'number' and 'T'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipTypeParameter.ts(51,16): error TS2365: Operator '<' cannot be applied to types 'E' and 'T'. +tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipTypeParameter.ts(51,16): error TS2365: Operator '<' cannot be applied to types 'number' and 'T'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipTypeParameter.ts(57,16): error TS2365: Operator '<' cannot be applied to types 'T' and 'number'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipTypeParameter.ts(60,16): error TS2365: Operator '<' cannot be applied to types 'T' and 'E'. +tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipTypeParameter.ts(60,16): error TS2365: Operator '<' cannot be applied to types 'T' and 'number'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipTypeParameter.ts(65,16): error TS2365: Operator '<' cannot be applied to types 'number' and 'T'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipTypeParameter.ts(68,16): error TS2365: Operator '<' cannot be applied to types 'E' and 'T'. +tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipTypeParameter.ts(68,16): error TS2365: Operator '<' cannot be applied to types 'number' and 'T'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipTypeParameter.ts(74,16): error TS2365: Operator '<' cannot be applied to types 'T' and 'number'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipTypeParameter.ts(77,16): error TS2365: Operator '<' cannot be applied to types 'T' and 'E'. +tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipTypeParameter.ts(77,16): error TS2365: Operator '<' cannot be applied to types 'T' and 'number'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipTypeParameter.ts(82,16): error TS2365: Operator '<' cannot be applied to types 'number' and 'T'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipTypeParameter.ts(85,16): error TS2365: Operator '<' cannot be applied to types 'E' and 'T'. +tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipTypeParameter.ts(85,16): error TS2365: Operator '<' cannot be applied to types 'number' and 'T'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipTypeParameter.ts(91,16): error TS2365: Operator '<' cannot be applied to types 'T' and 'number'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipTypeParameter.ts(94,16): error TS2365: Operator '<' cannot be applied to types 'T' and 'E'. +tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipTypeParameter.ts(94,16): error TS2365: Operator '<' cannot be applied to types 'T' and 'number'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipTypeParameter.ts(99,16): error TS2365: Operator '<' cannot be applied to types 'number' and 'T'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipTypeParameter.ts(102,16): error TS2365: Operator '<' cannot be applied to types 'E' and 'T'. +tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipTypeParameter.ts(102,16): error TS2365: Operator '<' cannot be applied to types 'number' and 'T'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipTypeParameter.ts(108,16): error TS2365: Operator '<' cannot be applied to types 'T' and 'number'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipTypeParameter.ts(111,16): error TS2365: Operator '<' cannot be applied to types 'T' and 'E'. +tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipTypeParameter.ts(111,16): error TS2365: Operator '<' cannot be applied to types 'T' and 'number'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipTypeParameter.ts(116,16): error TS2365: Operator '<' cannot be applied to types 'number' and 'T'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipTypeParameter.ts(119,16): error TS2365: Operator '<' cannot be applied to types 'E' and 'T'. +tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipTypeParameter.ts(119,16): error TS2365: Operator '<' cannot be applied to types 'number' and 'T'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipTypeParameter.ts(125,16): error TS2365: Operator '<' cannot be applied to types 'T' and 'number'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipTypeParameter.ts(128,16): error TS2365: Operator '<' cannot be applied to types 'T' and 'E'. +tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipTypeParameter.ts(128,16): error TS2365: Operator '<' cannot be applied to types 'T' and 'number'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipTypeParameter.ts(133,16): error TS2365: Operator '<' cannot be applied to types 'number' and 'T'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipTypeParameter.ts(136,16): error TS2365: Operator '<' cannot be applied to types 'E' and 'T'. +tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipTypeParameter.ts(136,16): error TS2365: Operator '<' cannot be applied to types 'number' and 'T'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipTypeParameter.ts(142,16): error TS2365: Operator '<' cannot be applied to types 'T' and 'number'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipTypeParameter.ts(145,16): error TS2365: Operator '<' cannot be applied to types 'T' and 'E'. +tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipTypeParameter.ts(145,16): error TS2365: Operator '<' cannot be applied to types 'T' and 'number'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipTypeParameter.ts(150,16): error TS2365: Operator '<' cannot be applied to types 'number' and 'T'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipTypeParameter.ts(153,16): error TS2365: Operator '<' cannot be applied to types 'E' and 'T'. +tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipTypeParameter.ts(153,16): error TS2365: Operator '<' cannot be applied to types 'number' and 'T'. ==== tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipTypeParameter.ts (40 errors) ==== @@ -86,7 +86,7 @@ tests/cases/conformance/expressions/binaryOperators/comparisonOperator/compariso var r1a4 = t < d; var r1a5 = t < e; ~~~~~ -!!! error TS2365: Operator '<' cannot be applied to types 'T' and 'E'. +!!! error TS2365: Operator '<' cannot be applied to types 'T' and 'number'. var r1a6 = t < f; var r1a7 = t < g; @@ -98,7 +98,7 @@ tests/cases/conformance/expressions/binaryOperators/comparisonOperator/compariso var r1b4 = d < t; var r1b5 = e < t; ~~~~~ -!!! error TS2365: Operator '<' cannot be applied to types 'E' and 'T'. +!!! error TS2365: Operator '<' cannot be applied to types 'number' and 'T'. var r1b6 = f < t; var r1b7 = g < t; @@ -111,7 +111,7 @@ tests/cases/conformance/expressions/binaryOperators/comparisonOperator/compariso var r2a4 = t < d; var r2a5 = t < e; ~~~~~ -!!! error TS2365: Operator '<' cannot be applied to types 'T' and 'E'. +!!! error TS2365: Operator '<' cannot be applied to types 'T' and 'number'. var r2a6 = t < f; var r2a7 = t < g; @@ -123,7 +123,7 @@ tests/cases/conformance/expressions/binaryOperators/comparisonOperator/compariso var r2b4 = d < t; var r2b5 = e < t; ~~~~~ -!!! error TS2365: Operator '<' cannot be applied to types 'E' and 'T'. +!!! error TS2365: Operator '<' cannot be applied to types 'number' and 'T'. var r2b6 = f < t; var r2b7 = g < t; @@ -136,7 +136,7 @@ tests/cases/conformance/expressions/binaryOperators/comparisonOperator/compariso var r3a4 = t < d; var r3a5 = t < e; ~~~~~ -!!! error TS2365: Operator '<' cannot be applied to types 'T' and 'E'. +!!! error TS2365: Operator '<' cannot be applied to types 'T' and 'number'. var r3a6 = t < f; var r3a7 = t < g; @@ -148,7 +148,7 @@ tests/cases/conformance/expressions/binaryOperators/comparisonOperator/compariso var r3b4 = d < t; var r3b5 = e < t; ~~~~~ -!!! error TS2365: Operator '<' cannot be applied to types 'E' and 'T'. +!!! error TS2365: Operator '<' cannot be applied to types 'number' and 'T'. var r3b6 = f < t; var r3b7 = g < t; @@ -161,7 +161,7 @@ tests/cases/conformance/expressions/binaryOperators/comparisonOperator/compariso var r4a4 = t < d; var r4a5 = t < e; ~~~~~ -!!! error TS2365: Operator '<' cannot be applied to types 'T' and 'E'. +!!! error TS2365: Operator '<' cannot be applied to types 'T' and 'number'. var r4a6 = t < f; var r4a7 = t < g; @@ -173,7 +173,7 @@ tests/cases/conformance/expressions/binaryOperators/comparisonOperator/compariso var r4b4 = d < t; var r4b5 = e < t; ~~~~~ -!!! error TS2365: Operator '<' cannot be applied to types 'E' and 'T'. +!!! error TS2365: Operator '<' cannot be applied to types 'number' and 'T'. var r4b6 = f < t; var r4b7 = g < t; @@ -186,7 +186,7 @@ tests/cases/conformance/expressions/binaryOperators/comparisonOperator/compariso var r5a4 = t < d; var r5a5 = t < e; ~~~~~ -!!! error TS2365: Operator '<' cannot be applied to types 'T' and 'E'. +!!! error TS2365: Operator '<' cannot be applied to types 'T' and 'number'. var r5a6 = t < f; var r5a7 = t < g; @@ -198,7 +198,7 @@ tests/cases/conformance/expressions/binaryOperators/comparisonOperator/compariso var r5b4 = d < t; var r5b5 = e < t; ~~~~~ -!!! error TS2365: Operator '<' cannot be applied to types 'E' and 'T'. +!!! error TS2365: Operator '<' cannot be applied to types 'number' and 'T'. var r5b6 = f < t; var r5b7 = g < t; @@ -211,7 +211,7 @@ tests/cases/conformance/expressions/binaryOperators/comparisonOperator/compariso var r6a4 = t < d; var r6a5 = t < e; ~~~~~ -!!! error TS2365: Operator '<' cannot be applied to types 'T' and 'E'. +!!! error TS2365: Operator '<' cannot be applied to types 'T' and 'number'. var r6a6 = t < f; var r6a7 = t < g; @@ -223,7 +223,7 @@ tests/cases/conformance/expressions/binaryOperators/comparisonOperator/compariso var r6b4 = d < t; var r6b5 = e < t; ~~~~~ -!!! error TS2365: Operator '<' cannot be applied to types 'E' and 'T'. +!!! error TS2365: Operator '<' cannot be applied to types 'number' and 'T'. var r6b6 = f < t; var r6b7 = g < t; @@ -236,7 +236,7 @@ tests/cases/conformance/expressions/binaryOperators/comparisonOperator/compariso var r7a4 = t < d; var r7a5 = t < e; ~~~~~ -!!! error TS2365: Operator '<' cannot be applied to types 'T' and 'E'. +!!! error TS2365: Operator '<' cannot be applied to types 'T' and 'number'. var r7a6 = t < f; var r7a7 = t < g; @@ -248,7 +248,7 @@ tests/cases/conformance/expressions/binaryOperators/comparisonOperator/compariso var r7b4 = d < t; var r7b5 = e < t; ~~~~~ -!!! error TS2365: Operator '<' cannot be applied to types 'E' and 'T'. +!!! error TS2365: Operator '<' cannot be applied to types 'number' and 'T'. var r7b6 = f < t; var r7b7 = g < t; @@ -261,7 +261,7 @@ tests/cases/conformance/expressions/binaryOperators/comparisonOperator/compariso var r8a4 = t < d; var r8a5 = t < e; ~~~~~ -!!! error TS2365: Operator '<' cannot be applied to types 'T' and 'E'. +!!! error TS2365: Operator '<' cannot be applied to types 'T' and 'number'. var r8a6 = t < f; var r8a7 = t < g; @@ -273,7 +273,7 @@ tests/cases/conformance/expressions/binaryOperators/comparisonOperator/compariso var r8b4 = d < t; var r8b5 = e < t; ~~~~~ -!!! error TS2365: Operator '<' cannot be applied to types 'E' and 'T'. +!!! error TS2365: Operator '<' cannot be applied to types 'number' and 'T'. var r8b6 = f < t; var r8b7 = g < t; } \ No newline at end of file diff --git a/tests/baselines/reference/mixedTypeEnumComparison.js b/tests/baselines/reference/mixedTypeEnumComparison.js new file mode 100644 index 0000000000000..b461f67f0e828 --- /dev/null +++ b/tests/baselines/reference/mixedTypeEnumComparison.js @@ -0,0 +1,61 @@ +//// [mixedTypeEnumComparison.ts] +const enum E { + S1 = "foo", + S2 = "bar", + + N1 = 1000, + N2 = 25, +} + +declare var someNumber: number + +if (someNumber > E.N2) { + someNumber = E.N2; +} + +declare const unionOfEnum: E.N1 | E.N2; + +if (someNumber > unionOfEnum) { + someNumber = E.N2; +} + +declare var someString: string + +if (someString > E.S1) { + someString = E.S2; +} + + +declare function someValue(): number; + +enum E2 { + S1 = "foo", + N1 = 1000, + C1 = someValue(), +} + +someString > E2.S1; +someNumber > E2.N1; +someNumber > E2.C1; + + +//// [mixedTypeEnumComparison.js] +"use strict"; +if (someNumber > 25 /* E.N2 */) { + someNumber = 25 /* E.N2 */; +} +if (someNumber > unionOfEnum) { + someNumber = 25 /* E.N2 */; +} +if (someString > "foo" /* E.S1 */) { + someString = "bar" /* E.S2 */; +} +var E2; +(function (E2) { + E2["S1"] = "foo"; + E2[E2["N1"] = 1000] = "N1"; + E2[E2["C1"] = someValue()] = "C1"; +})(E2 || (E2 = {})); +someString > E2.S1; +someNumber > E2.N1; +someNumber > E2.C1; diff --git a/tests/baselines/reference/mixedTypeEnumComparison.symbols b/tests/baselines/reference/mixedTypeEnumComparison.symbols new file mode 100644 index 0000000000000..7d0f087848295 --- /dev/null +++ b/tests/baselines/reference/mixedTypeEnumComparison.symbols @@ -0,0 +1,103 @@ +=== tests/cases/compiler/mixedTypeEnumComparison.ts === +const enum E { +>E : Symbol(E, Decl(mixedTypeEnumComparison.ts, 0, 0)) + + S1 = "foo", +>S1 : Symbol(E.S1, Decl(mixedTypeEnumComparison.ts, 0, 14)) + + S2 = "bar", +>S2 : Symbol(E.S2, Decl(mixedTypeEnumComparison.ts, 1, 15)) + + N1 = 1000, +>N1 : Symbol(E.N1, Decl(mixedTypeEnumComparison.ts, 2, 15)) + + N2 = 25, +>N2 : Symbol(E.N2, Decl(mixedTypeEnumComparison.ts, 4, 14)) +} + +declare var someNumber: number +>someNumber : Symbol(someNumber, Decl(mixedTypeEnumComparison.ts, 8, 11)) + +if (someNumber > E.N2) { +>someNumber : Symbol(someNumber, Decl(mixedTypeEnumComparison.ts, 8, 11)) +>E.N2 : Symbol(E.N2, Decl(mixedTypeEnumComparison.ts, 4, 14)) +>E : Symbol(E, Decl(mixedTypeEnumComparison.ts, 0, 0)) +>N2 : Symbol(E.N2, Decl(mixedTypeEnumComparison.ts, 4, 14)) + + someNumber = E.N2; +>someNumber : Symbol(someNumber, Decl(mixedTypeEnumComparison.ts, 8, 11)) +>E.N2 : Symbol(E.N2, Decl(mixedTypeEnumComparison.ts, 4, 14)) +>E : Symbol(E, Decl(mixedTypeEnumComparison.ts, 0, 0)) +>N2 : Symbol(E.N2, Decl(mixedTypeEnumComparison.ts, 4, 14)) +} + +declare const unionOfEnum: E.N1 | E.N2; +>unionOfEnum : Symbol(unionOfEnum, Decl(mixedTypeEnumComparison.ts, 14, 13)) +>E : Symbol(E, Decl(mixedTypeEnumComparison.ts, 0, 0)) +>N1 : Symbol(E.N1, Decl(mixedTypeEnumComparison.ts, 2, 15)) +>E : Symbol(E, Decl(mixedTypeEnumComparison.ts, 0, 0)) +>N2 : Symbol(E.N2, Decl(mixedTypeEnumComparison.ts, 4, 14)) + +if (someNumber > unionOfEnum) { +>someNumber : Symbol(someNumber, Decl(mixedTypeEnumComparison.ts, 8, 11)) +>unionOfEnum : Symbol(unionOfEnum, Decl(mixedTypeEnumComparison.ts, 14, 13)) + + someNumber = E.N2; +>someNumber : Symbol(someNumber, Decl(mixedTypeEnumComparison.ts, 8, 11)) +>E.N2 : Symbol(E.N2, Decl(mixedTypeEnumComparison.ts, 4, 14)) +>E : Symbol(E, Decl(mixedTypeEnumComparison.ts, 0, 0)) +>N2 : Symbol(E.N2, Decl(mixedTypeEnumComparison.ts, 4, 14)) +} + +declare var someString: string +>someString : Symbol(someString, Decl(mixedTypeEnumComparison.ts, 20, 11)) + +if (someString > E.S1) { +>someString : Symbol(someString, Decl(mixedTypeEnumComparison.ts, 20, 11)) +>E.S1 : Symbol(E.S1, Decl(mixedTypeEnumComparison.ts, 0, 14)) +>E : Symbol(E, Decl(mixedTypeEnumComparison.ts, 0, 0)) +>S1 : Symbol(E.S1, Decl(mixedTypeEnumComparison.ts, 0, 14)) + + someString = E.S2; +>someString : Symbol(someString, Decl(mixedTypeEnumComparison.ts, 20, 11)) +>E.S2 : Symbol(E.S2, Decl(mixedTypeEnumComparison.ts, 1, 15)) +>E : Symbol(E, Decl(mixedTypeEnumComparison.ts, 0, 0)) +>S2 : Symbol(E.S2, Decl(mixedTypeEnumComparison.ts, 1, 15)) +} + + +declare function someValue(): number; +>someValue : Symbol(someValue, Decl(mixedTypeEnumComparison.ts, 24, 1)) + +enum E2 { +>E2 : Symbol(E2, Decl(mixedTypeEnumComparison.ts, 27, 37)) + + S1 = "foo", +>S1 : Symbol(E2.S1, Decl(mixedTypeEnumComparison.ts, 29, 9)) + + N1 = 1000, +>N1 : Symbol(E2.N1, Decl(mixedTypeEnumComparison.ts, 30, 15)) + + C1 = someValue(), +>C1 : Symbol(E2.C1, Decl(mixedTypeEnumComparison.ts, 31, 14)) +>someValue : Symbol(someValue, Decl(mixedTypeEnumComparison.ts, 24, 1)) +} + +someString > E2.S1; +>someString : Symbol(someString, Decl(mixedTypeEnumComparison.ts, 20, 11)) +>E2.S1 : Symbol(E2.S1, Decl(mixedTypeEnumComparison.ts, 29, 9)) +>E2 : Symbol(E2, Decl(mixedTypeEnumComparison.ts, 27, 37)) +>S1 : Symbol(E2.S1, Decl(mixedTypeEnumComparison.ts, 29, 9)) + +someNumber > E2.N1; +>someNumber : Symbol(someNumber, Decl(mixedTypeEnumComparison.ts, 8, 11)) +>E2.N1 : Symbol(E2.N1, Decl(mixedTypeEnumComparison.ts, 30, 15)) +>E2 : Symbol(E2, Decl(mixedTypeEnumComparison.ts, 27, 37)) +>N1 : Symbol(E2.N1, Decl(mixedTypeEnumComparison.ts, 30, 15)) + +someNumber > E2.C1; +>someNumber : Symbol(someNumber, Decl(mixedTypeEnumComparison.ts, 8, 11)) +>E2.C1 : Symbol(E2.C1, Decl(mixedTypeEnumComparison.ts, 31, 14)) +>E2 : Symbol(E2, Decl(mixedTypeEnumComparison.ts, 27, 37)) +>C1 : Symbol(E2.C1, Decl(mixedTypeEnumComparison.ts, 31, 14)) + diff --git a/tests/baselines/reference/mixedTypeEnumComparison.types b/tests/baselines/reference/mixedTypeEnumComparison.types new file mode 100644 index 0000000000000..3f9c1cb44fc08 --- /dev/null +++ b/tests/baselines/reference/mixedTypeEnumComparison.types @@ -0,0 +1,117 @@ +=== tests/cases/compiler/mixedTypeEnumComparison.ts === +const enum E { +>E : E + + S1 = "foo", +>S1 : E.S1 +>"foo" : "foo" + + S2 = "bar", +>S2 : E.S2 +>"bar" : "bar" + + N1 = 1000, +>N1 : E.N1 +>1000 : 1000 + + N2 = 25, +>N2 : E.N2 +>25 : 25 +} + +declare var someNumber: number +>someNumber : number + +if (someNumber > E.N2) { +>someNumber > E.N2 : boolean +>someNumber : number +>E.N2 : E.N2 +>E : typeof E +>N2 : E.N2 + + someNumber = E.N2; +>someNumber = E.N2 : E.N2 +>someNumber : number +>E.N2 : E.N2 +>E : typeof E +>N2 : E.N2 +} + +declare const unionOfEnum: E.N1 | E.N2; +>unionOfEnum : E.N1 | E.N2 +>E : any +>E : any + +if (someNumber > unionOfEnum) { +>someNumber > unionOfEnum : boolean +>someNumber : number +>unionOfEnum : E.N1 | E.N2 + + someNumber = E.N2; +>someNumber = E.N2 : E.N2 +>someNumber : number +>E.N2 : E.N2 +>E : typeof E +>N2 : E.N2 +} + +declare var someString: string +>someString : string + +if (someString > E.S1) { +>someString > E.S1 : boolean +>someString : string +>E.S1 : E.S1 +>E : typeof E +>S1 : E.S1 + + someString = E.S2; +>someString = E.S2 : E.S2 +>someString : string +>E.S2 : E.S2 +>E : typeof E +>S2 : E.S2 +} + + +declare function someValue(): number; +>someValue : () => number + +enum E2 { +>E2 : E2 + + S1 = "foo", +>S1 : E2.S1 +>"foo" : "foo" + + N1 = 1000, +>N1 : E2.N1 +>1000 : 1000 + + C1 = someValue(), +>C1 : E2.C1 +>someValue() : number +>someValue : () => number +} + +someString > E2.S1; +>someString > E2.S1 : boolean +>someString : string +>E2.S1 : E2.S1 +>E2 : typeof E2 +>S1 : E2.S1 + +someNumber > E2.N1; +>someNumber > E2.N1 : boolean +>someNumber : number +>E2.N1 : E2.N1 +>E2 : typeof E2 +>N1 : E2.N1 + +someNumber > E2.C1; +>someNumber > E2.C1 : boolean +>someNumber : number +>E2.C1 : E2.C1 +>E2 : typeof E2 +>C1 : E2.C1 + diff --git a/tests/cases/compiler/mixedTypeEnumComparison.ts b/tests/cases/compiler/mixedTypeEnumComparison.ts new file mode 100644 index 0000000000000..7baa6d77b4717 --- /dev/null +++ b/tests/cases/compiler/mixedTypeEnumComparison.ts @@ -0,0 +1,40 @@ +// @strict: true + +const enum E { + S1 = "foo", + S2 = "bar", + + N1 = 1000, + N2 = 25, +} + +declare var someNumber: number + +if (someNumber > E.N2) { + someNumber = E.N2; +} + +declare const unionOfEnum: E.N1 | E.N2; + +if (someNumber > unionOfEnum) { + someNumber = E.N2; +} + +declare var someString: string + +if (someString > E.S1) { + someString = E.S2; +} + + +declare function someValue(): number; + +enum E2 { + S1 = "foo", + N1 = 1000, + C1 = someValue(), +} + +someString > E2.S1; +someNumber > E2.N1; +someNumber > E2.C1;