Fix type parameter comparability to consistently allow comparisons on unconstrained type parameters (#48861)

* Fix type parameter comparability to consistently allow comparisons on unconstrained type parameters

* Less elaboration, non-strict-mode fix
This commit is contained in:
Wesley Wigham 2022-05-09 12:22:00 -07:00 committed by GitHub
parent 1071240907
commit f84ec3e8b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 291 additions and 351 deletions

View File

@ -19347,6 +19347,20 @@ namespace ts {
}
}
}
if (relation === comparableRelation && sourceFlags & TypeFlags.TypeParameter) {
// This is a carve-out in comparability to essentially forbid comparing a type parameter
// with another type parameter unless one extends the other. (Remember: comparability is mostly bidirectional!)
let constraint = getConstraintOfTypeParameter(source);
if (constraint && hasNonCircularBaseConstraint(source)) {
while (constraint && constraint.flags & TypeFlags.TypeParameter) {
if (result = isRelatedTo(constraint, target, RecursionFlags.Source, /*reportErrors*/ false)) {
return result;
}
constraint = getConstraintOfTypeParameter(constraint);
}
}
return Ternary.False;
}
}
else if (targetFlags & TypeFlags.Index) {
const targetType = (target as IndexType).type;
@ -19558,8 +19572,8 @@ namespace ts {
if (sourceFlags & TypeFlags.TypeVariable) {
// IndexedAccess comparisons are handled above in the `targetFlags & TypeFlage.IndexedAccess` branch
if (!(sourceFlags & TypeFlags.IndexedAccess && targetFlags & TypeFlags.IndexedAccess)) {
const constraint = getConstraintOfType(source as TypeVariable);
if (!constraint || (sourceFlags & TypeFlags.TypeParameter && constraint.flags & TypeFlags.Any)) {
const constraint = getConstraintOfType(source as TypeVariable) || unknownType;
if (!getConstraintOfType(source as TypeVariable) || (sourceFlags & TypeFlags.TypeParameter && constraint.flags & TypeFlags.Any)) {
// A type variable with no constraint is not related to the non-primitive object type.
if (result = isRelatedTo(emptyObjectType, extractTypesOfKind(target, ~TypeFlags.NonPrimitive), RecursionFlags.Both)) {
resetErrorInfo(saveErrorInfo);
@ -19567,12 +19581,12 @@ namespace ts {
}
}
// hi-speed no-this-instantiation check (less accurate, but avoids costly `this`-instantiation when the constraint will suffice), see #28231 for report on why this is needed
else if (result = isRelatedTo(constraint, target, RecursionFlags.Source, /*reportErrors*/ false, /*headMessage*/ undefined, intersectionState)) {
if (result = isRelatedTo(constraint, target, RecursionFlags.Source, /*reportErrors*/ false, /*headMessage*/ undefined, intersectionState)) {
resetErrorInfo(saveErrorInfo);
return result;
}
// slower, fuller, this-instantiated check (necessary when comparing raw `this` types from base classes), see `subclassWithPolymorphicThisIsAssignable.ts` test for example
else if (result = isRelatedTo(getTypeWithThisArgument(constraint, source), target, RecursionFlags.Source, reportErrors && !(targetFlags & sourceFlags & TypeFlags.TypeParameter), /*headMessage*/ undefined, intersectionState)) {
else if (result = isRelatedTo(getTypeWithThisArgument(constraint, source), target, RecursionFlags.Source, reportErrors && constraint !== unknownType && !(targetFlags & sourceFlags & TypeFlags.TypeParameter), /*headMessage*/ undefined, intersectionState)) {
resetErrorInfo(saveErrorInfo);
return result;
}

View File

@ -6,121 +6,9 @@ tests/cases/conformance/expressions/binaryOperators/comparisonOperator/compariso
tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipTypeParameter.ts(17,14): error TS2367: This condition will always return 'true' since the types 'T' and 'U' have no overlap.
tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipTypeParameter.ts(18,14): error TS2367: This condition will always return 'false' since the types 'T' and 'U' have no overlap.
tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipTypeParameter.ts(19,14): error TS2367: This condition will always return 'true' since the types 'T' and 'U' have no overlap.
tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipTypeParameter.ts(22,16): error TS2365: Operator '<' cannot be applied to types 'T' and 'boolean'.
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(24,16): error TS2365: Operator '<' cannot be applied to types 'T' and 'string'.
tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipTypeParameter.ts(25,16): error TS2365: Operator '<' cannot be applied to types 'T' and 'void'.
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(27,16): error TS2365: Operator '<' cannot be applied to types 'T' and '{ a: string; }'.
tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipTypeParameter.ts(28,16): error TS2365: Operator '<' cannot be applied to types 'T' and 'any[]'.
tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipTypeParameter.ts(30,16): error TS2365: Operator '<' cannot be applied to types 'boolean' and 'T'.
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(32,16): error TS2365: Operator '<' cannot be applied to types 'string' and 'T'.
tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipTypeParameter.ts(33,16): error TS2365: Operator '<' cannot be applied to types 'void' 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(35,16): error TS2365: Operator '<' cannot be applied to types '{ a: string; }' and 'T'.
tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipTypeParameter.ts(36,16): error TS2365: Operator '<' cannot be applied to types 'any[]' and 'T'.
tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipTypeParameter.ts(39,16): error TS2365: Operator '<' cannot be applied to types 'T' and 'boolean'.
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(41,16): error TS2365: Operator '<' cannot be applied to types 'T' and 'string'.
tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipTypeParameter.ts(42,16): error TS2365: Operator '<' cannot be applied to types 'T' and 'void'.
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(44,16): error TS2365: Operator '<' cannot be applied to types 'T' and '{ a: string; }'.
tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipTypeParameter.ts(45,16): error TS2365: Operator '<' cannot be applied to types 'T' and 'any[]'.
tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipTypeParameter.ts(47,16): error TS2365: Operator '<' cannot be applied to types 'boolean' and 'T'.
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(49,16): error TS2365: Operator '<' cannot be applied to types 'string' and 'T'.
tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipTypeParameter.ts(50,16): error TS2365: Operator '<' cannot be applied to types 'void' 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(52,16): error TS2365: Operator '<' cannot be applied to types '{ a: string; }' and 'T'.
tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipTypeParameter.ts(53,16): error TS2365: Operator '<' cannot be applied to types 'any[]' and 'T'.
tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipTypeParameter.ts(56,16): error TS2365: Operator '<' cannot be applied to types 'T' and 'boolean'.
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(58,16): error TS2365: Operator '<' cannot be applied to types 'T' and 'string'.
tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipTypeParameter.ts(59,16): error TS2365: Operator '<' cannot be applied to types 'T' and 'void'.
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(61,16): error TS2365: Operator '<' cannot be applied to types 'T' and '{ a: string; }'.
tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipTypeParameter.ts(62,16): error TS2365: Operator '<' cannot be applied to types 'T' and 'any[]'.
tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipTypeParameter.ts(64,16): error TS2365: Operator '<' cannot be applied to types 'boolean' and 'T'.
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(66,16): error TS2365: Operator '<' cannot be applied to types 'string' and 'T'.
tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipTypeParameter.ts(67,16): error TS2365: Operator '<' cannot be applied to types 'void' 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(69,16): error TS2365: Operator '<' cannot be applied to types '{ a: string; }' and 'T'.
tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipTypeParameter.ts(70,16): error TS2365: Operator '<' cannot be applied to types 'any[]' and 'T'.
tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipTypeParameter.ts(73,16): error TS2365: Operator '<' cannot be applied to types 'T' and 'boolean'.
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(75,16): error TS2365: Operator '<' cannot be applied to types 'T' and 'string'.
tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipTypeParameter.ts(76,16): error TS2365: Operator '<' cannot be applied to types 'T' and 'void'.
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(78,16): error TS2365: Operator '<' cannot be applied to types 'T' and '{ a: string; }'.
tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipTypeParameter.ts(79,16): error TS2365: Operator '<' cannot be applied to types 'T' and 'any[]'.
tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipTypeParameter.ts(81,16): error TS2365: Operator '<' cannot be applied to types 'boolean' and 'T'.
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(83,16): error TS2365: Operator '<' cannot be applied to types 'string' and 'T'.
tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipTypeParameter.ts(84,16): error TS2365: Operator '<' cannot be applied to types 'void' 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(86,16): error TS2365: Operator '<' cannot be applied to types '{ a: string; }' and 'T'.
tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipTypeParameter.ts(87,16): error TS2365: Operator '<' cannot be applied to types 'any[]' and 'T'.
tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipTypeParameter.ts(90,16): error TS2365: Operator '<' cannot be applied to types 'T' and 'boolean'.
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(92,16): error TS2365: Operator '<' cannot be applied to types 'T' and 'string'.
tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipTypeParameter.ts(93,16): error TS2365: Operator '<' cannot be applied to types 'T' and 'void'.
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(95,16): error TS2365: Operator '<' cannot be applied to types 'T' and '{ a: string; }'.
tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipTypeParameter.ts(96,16): error TS2365: Operator '<' cannot be applied to types 'T' and 'any[]'.
tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipTypeParameter.ts(98,16): error TS2365: Operator '<' cannot be applied to types 'boolean' and 'T'.
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(100,16): error TS2365: Operator '<' cannot be applied to types 'string' and 'T'.
tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipTypeParameter.ts(101,16): error TS2365: Operator '<' cannot be applied to types 'void' 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(103,16): error TS2365: Operator '<' cannot be applied to types '{ a: string; }' and 'T'.
tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipTypeParameter.ts(104,16): error TS2365: Operator '<' cannot be applied to types 'any[]' and 'T'.
tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipTypeParameter.ts(107,16): error TS2365: Operator '<' cannot be applied to types 'T' and 'boolean'.
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(109,16): error TS2365: Operator '<' cannot be applied to types 'T' and 'string'.
tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipTypeParameter.ts(110,16): error TS2365: Operator '<' cannot be applied to types 'T' and 'void'.
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(112,16): error TS2365: Operator '<' cannot be applied to types 'T' and '{ a: string; }'.
tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipTypeParameter.ts(113,16): error TS2365: Operator '<' cannot be applied to types 'T' and 'any[]'.
tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipTypeParameter.ts(115,16): error TS2365: Operator '<' cannot be applied to types 'boolean' and 'T'.
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(117,16): error TS2365: Operator '<' cannot be applied to types 'string' and 'T'.
tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipTypeParameter.ts(118,16): error TS2365: Operator '<' cannot be applied to types 'void' 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(120,16): error TS2365: Operator '<' cannot be applied to types '{ a: string; }' and 'T'.
tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipTypeParameter.ts(121,16): error TS2365: Operator '<' cannot be applied to types 'any[]' and 'T'.
tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipTypeParameter.ts(124,16): error TS2365: Operator '<' cannot be applied to types 'T' and 'boolean'.
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(126,16): error TS2365: Operator '<' cannot be applied to types 'T' and 'string'.
tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipTypeParameter.ts(127,16): error TS2365: Operator '<' cannot be applied to types 'T' and 'void'.
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(129,16): error TS2365: Operator '<' cannot be applied to types 'T' and '{ a: string; }'.
tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipTypeParameter.ts(130,16): error TS2365: Operator '<' cannot be applied to types 'T' and 'any[]'.
tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipTypeParameter.ts(132,16): error TS2365: Operator '<' cannot be applied to types 'boolean' and 'T'.
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(134,16): error TS2365: Operator '<' cannot be applied to types 'string' and 'T'.
tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipTypeParameter.ts(135,16): error TS2365: Operator '<' cannot be applied to types 'void' 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(137,16): error TS2365: Operator '<' cannot be applied to types '{ a: string; }' and 'T'.
tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipTypeParameter.ts(138,16): error TS2365: Operator '<' cannot be applied to types 'any[]' and 'T'.
tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipTypeParameter.ts(141,16): error TS2365: Operator '<' cannot be applied to types 'T' and 'boolean'.
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(143,16): error TS2365: Operator '<' cannot be applied to types 'T' and 'string'.
tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipTypeParameter.ts(144,16): error TS2365: Operator '<' cannot be applied to types 'T' and 'void'.
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(146,16): error TS2365: Operator '<' cannot be applied to types 'T' and '{ a: string; }'.
tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipTypeParameter.ts(147,16): error TS2365: Operator '<' cannot be applied to types 'T' and 'any[]'.
tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipTypeParameter.ts(149,16): error TS2365: Operator '<' cannot be applied to types 'boolean' and 'T'.
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(151,16): error TS2365: Operator '<' cannot be applied to types 'string' and 'T'.
tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipTypeParameter.ts(152,16): error TS2365: Operator '<' cannot be applied to types 'void' 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(154,16): error TS2365: Operator '<' cannot be applied to types '{ a: string; }' and 'T'.
tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipTypeParameter.ts(155,16): error TS2365: Operator '<' cannot be applied to types 'any[]' and 'T'.
==== tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipTypeParameter.ts (120 errors) ====
==== tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipTypeParameter.ts (8 errors) ====
enum E { a, b, c }
var a: boolean;
@ -159,361 +47,137 @@ tests/cases/conformance/expressions/binaryOperators/comparisonOperator/compariso
// operator <
var r1a1 = t < a;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'T' and 'boolean'.
var r1a2 = t < b;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'T' and 'number'.
var r1a3 = t < c;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'T' and 'string'.
var r1a4 = t < d;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'T' and 'void'.
var r1a5 = t < e;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'T' and 'E'.
var r1a6 = t < f;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'T' and '{ a: string; }'.
var r1a7 = t < g;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'T' and 'any[]'.
var r1b1 = a < t;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'boolean' and 'T'.
var r1b2 = b < t;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'number' and 'T'.
var r1b3 = c < t;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'string' and 'T'.
var r1b4 = d < t;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'void' and 'T'.
var r1b5 = e < t;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'E' and 'T'.
var r1b6 = f < t;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types '{ a: string; }' and 'T'.
var r1b7 = g < t;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'any[]' and 'T'.
// operator >
var r2a1 = t < a;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'T' and 'boolean'.
var r2a2 = t < b;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'T' and 'number'.
var r2a3 = t < c;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'T' and 'string'.
var r2a4 = t < d;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'T' and 'void'.
var r2a5 = t < e;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'T' and 'E'.
var r2a6 = t < f;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'T' and '{ a: string; }'.
var r2a7 = t < g;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'T' and 'any[]'.
var r2b1 = a < t;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'boolean' and 'T'.
var r2b2 = b < t;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'number' and 'T'.
var r2b3 = c < t;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'string' and 'T'.
var r2b4 = d < t;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'void' and 'T'.
var r2b5 = e < t;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'E' and 'T'.
var r2b6 = f < t;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types '{ a: string; }' and 'T'.
var r2b7 = g < t;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'any[]' and 'T'.
// operator <=
var r3a1 = t < a;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'T' and 'boolean'.
var r3a2 = t < b;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'T' and 'number'.
var r3a3 = t < c;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'T' and 'string'.
var r3a4 = t < d;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'T' and 'void'.
var r3a5 = t < e;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'T' and 'E'.
var r3a6 = t < f;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'T' and '{ a: string; }'.
var r3a7 = t < g;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'T' and 'any[]'.
var r3b1 = a < t;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'boolean' and 'T'.
var r3b2 = b < t;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'number' and 'T'.
var r3b3 = c < t;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'string' and 'T'.
var r3b4 = d < t;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'void' and 'T'.
var r3b5 = e < t;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'E' and 'T'.
var r3b6 = f < t;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types '{ a: string; }' and 'T'.
var r3b7 = g < t;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'any[]' and 'T'.
// operator >=
var r4a1 = t < a;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'T' and 'boolean'.
var r4a2 = t < b;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'T' and 'number'.
var r4a3 = t < c;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'T' and 'string'.
var r4a4 = t < d;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'T' and 'void'.
var r4a5 = t < e;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'T' and 'E'.
var r4a6 = t < f;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'T' and '{ a: string; }'.
var r4a7 = t < g;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'T' and 'any[]'.
var r4b1 = a < t;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'boolean' and 'T'.
var r4b2 = b < t;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'number' and 'T'.
var r4b3 = c < t;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'string' and 'T'.
var r4b4 = d < t;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'void' and 'T'.
var r4b5 = e < t;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'E' and 'T'.
var r4b6 = f < t;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types '{ a: string; }' and 'T'.
var r4b7 = g < t;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'any[]' and 'T'.
// operator ==
var r5a1 = t < a;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'T' and 'boolean'.
var r5a2 = t < b;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'T' and 'number'.
var r5a3 = t < c;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'T' and 'string'.
var r5a4 = t < d;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'T' and 'void'.
var r5a5 = t < e;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'T' and 'E'.
var r5a6 = t < f;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'T' and '{ a: string; }'.
var r5a7 = t < g;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'T' and 'any[]'.
var r5b1 = a < t;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'boolean' and 'T'.
var r5b2 = b < t;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'number' and 'T'.
var r5b3 = c < t;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'string' and 'T'.
var r5b4 = d < t;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'void' and 'T'.
var r5b5 = e < t;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'E' and 'T'.
var r5b6 = f < t;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types '{ a: string; }' and 'T'.
var r5b7 = g < t;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'any[]' and 'T'.
// operator !=
var r6a1 = t < a;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'T' and 'boolean'.
var r6a2 = t < b;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'T' and 'number'.
var r6a3 = t < c;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'T' and 'string'.
var r6a4 = t < d;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'T' and 'void'.
var r6a5 = t < e;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'T' and 'E'.
var r6a6 = t < f;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'T' and '{ a: string; }'.
var r6a7 = t < g;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'T' and 'any[]'.
var r6b1 = a < t;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'boolean' and 'T'.
var r6b2 = b < t;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'number' and 'T'.
var r6b3 = c < t;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'string' and 'T'.
var r6b4 = d < t;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'void' and 'T'.
var r6b5 = e < t;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'E' and 'T'.
var r6b6 = f < t;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types '{ a: string; }' and 'T'.
var r6b7 = g < t;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'any[]' and 'T'.
// operator ===
var r7a1 = t < a;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'T' and 'boolean'.
var r7a2 = t < b;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'T' and 'number'.
var r7a3 = t < c;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'T' and 'string'.
var r7a4 = t < d;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'T' and 'void'.
var r7a5 = t < e;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'T' and 'E'.
var r7a6 = t < f;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'T' and '{ a: string; }'.
var r7a7 = t < g;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'T' and 'any[]'.
var r7b1 = a < t;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'boolean' and 'T'.
var r7b2 = b < t;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'number' and 'T'.
var r7b3 = c < t;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'string' and 'T'.
var r7b4 = d < t;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'void' and 'T'.
var r7b5 = e < t;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'E' and 'T'.
var r7b6 = f < t;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types '{ a: string; }' and 'T'.
var r7b7 = g < t;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'any[]' and 'T'.
// operator !==
var r8a1 = t < a;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'T' and 'boolean'.
var r8a2 = t < b;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'T' and 'number'.
var r8a3 = t < c;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'T' and 'string'.
var r8a4 = t < d;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'T' and 'void'.
var r8a5 = t < e;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'T' and 'E'.
var r8a6 = t < f;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'T' and '{ a: string; }'.
var r8a7 = t < g;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'T' and 'any[]'.
var r8b1 = a < t;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'boolean' and 'T'.
var r8b2 = b < t;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'number' and 'T'.
var r8b3 = c < t;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'string' and 'T'.
var r8b4 = d < t;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'void' and 'T'.
var r8b5 = e < t;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'E' and 'T'.
var r8b6 = f < t;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types '{ a: string; }' and 'T'.
var r8b7 = g < t;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'any[]' and 'T'.
}

View File

@ -0,0 +1,37 @@
tests/cases/compiler/genericWithNoConstraintComparableWithCurlyCurly.ts(23,5): error TS2352: Conversion of type '{}' to type 'T' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
'T' could be instantiated with an arbitrary type which could be unrelated to '{}'.
==== tests/cases/compiler/genericWithNoConstraintComparableWithCurlyCurly.ts (1 errors) ====
function foo<T>() {
let x = {};
x as T;
}
function bar<T extends unknown>() {
let x = {};
x as T;
}
function baz<T extends {}>() {
let x = {};
x as T;
}
function bat<T extends object>() {
let x = {};
x as T;
}
function no<T extends null | undefined>() {
let x = {};
x as T; // should error
~~~~~~
!!! error TS2352: Conversion of type '{}' to type 'T' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
!!! error TS2352: 'T' could be instantiated with an arbitrary type which could be unrelated to '{}'.
}
function yes<T extends object | null | undefined>() {
let x = {};
x as T;
}

View File

@ -0,0 +1,57 @@
//// [genericWithNoConstraintComparableWithCurlyCurly.ts]
function foo<T>() {
let x = {};
x as T;
}
function bar<T extends unknown>() {
let x = {};
x as T;
}
function baz<T extends {}>() {
let x = {};
x as T;
}
function bat<T extends object>() {
let x = {};
x as T;
}
function no<T extends null | undefined>() {
let x = {};
x as T; // should error
}
function yes<T extends object | null | undefined>() {
let x = {};
x as T;
}
//// [genericWithNoConstraintComparableWithCurlyCurly.js]
"use strict";
function foo() {
var x = {};
x;
}
function bar() {
var x = {};
x;
}
function baz() {
var x = {};
x;
}
function bat() {
var x = {};
x;
}
function no() {
var x = {};
x; // should error
}
function yes() {
var x = {};
x;
}

View File

@ -0,0 +1,72 @@
=== tests/cases/compiler/genericWithNoConstraintComparableWithCurlyCurly.ts ===
function foo<T>() {
>foo : Symbol(foo, Decl(genericWithNoConstraintComparableWithCurlyCurly.ts, 0, 0))
>T : Symbol(T, Decl(genericWithNoConstraintComparableWithCurlyCurly.ts, 0, 13))
let x = {};
>x : Symbol(x, Decl(genericWithNoConstraintComparableWithCurlyCurly.ts, 1, 7))
x as T;
>x : Symbol(x, Decl(genericWithNoConstraintComparableWithCurlyCurly.ts, 1, 7))
>T : Symbol(T, Decl(genericWithNoConstraintComparableWithCurlyCurly.ts, 0, 13))
}
function bar<T extends unknown>() {
>bar : Symbol(bar, Decl(genericWithNoConstraintComparableWithCurlyCurly.ts, 3, 1))
>T : Symbol(T, Decl(genericWithNoConstraintComparableWithCurlyCurly.ts, 5, 13))
let x = {};
>x : Symbol(x, Decl(genericWithNoConstraintComparableWithCurlyCurly.ts, 6, 7))
x as T;
>x : Symbol(x, Decl(genericWithNoConstraintComparableWithCurlyCurly.ts, 6, 7))
>T : Symbol(T, Decl(genericWithNoConstraintComparableWithCurlyCurly.ts, 5, 13))
}
function baz<T extends {}>() {
>baz : Symbol(baz, Decl(genericWithNoConstraintComparableWithCurlyCurly.ts, 8, 1))
>T : Symbol(T, Decl(genericWithNoConstraintComparableWithCurlyCurly.ts, 10, 13))
let x = {};
>x : Symbol(x, Decl(genericWithNoConstraintComparableWithCurlyCurly.ts, 11, 7))
x as T;
>x : Symbol(x, Decl(genericWithNoConstraintComparableWithCurlyCurly.ts, 11, 7))
>T : Symbol(T, Decl(genericWithNoConstraintComparableWithCurlyCurly.ts, 10, 13))
}
function bat<T extends object>() {
>bat : Symbol(bat, Decl(genericWithNoConstraintComparableWithCurlyCurly.ts, 13, 1))
>T : Symbol(T, Decl(genericWithNoConstraintComparableWithCurlyCurly.ts, 15, 13))
let x = {};
>x : Symbol(x, Decl(genericWithNoConstraintComparableWithCurlyCurly.ts, 16, 7))
x as T;
>x : Symbol(x, Decl(genericWithNoConstraintComparableWithCurlyCurly.ts, 16, 7))
>T : Symbol(T, Decl(genericWithNoConstraintComparableWithCurlyCurly.ts, 15, 13))
}
function no<T extends null | undefined>() {
>no : Symbol(no, Decl(genericWithNoConstraintComparableWithCurlyCurly.ts, 18, 1))
>T : Symbol(T, Decl(genericWithNoConstraintComparableWithCurlyCurly.ts, 20, 12))
let x = {};
>x : Symbol(x, Decl(genericWithNoConstraintComparableWithCurlyCurly.ts, 21, 7))
x as T; // should error
>x : Symbol(x, Decl(genericWithNoConstraintComparableWithCurlyCurly.ts, 21, 7))
>T : Symbol(T, Decl(genericWithNoConstraintComparableWithCurlyCurly.ts, 20, 12))
}
function yes<T extends object | null | undefined>() {
>yes : Symbol(yes, Decl(genericWithNoConstraintComparableWithCurlyCurly.ts, 23, 1))
>T : Symbol(T, Decl(genericWithNoConstraintComparableWithCurlyCurly.ts, 25, 13))
let x = {};
>x : Symbol(x, Decl(genericWithNoConstraintComparableWithCurlyCurly.ts, 26, 7))
x as T;
>x : Symbol(x, Decl(genericWithNoConstraintComparableWithCurlyCurly.ts, 26, 7))
>T : Symbol(T, Decl(genericWithNoConstraintComparableWithCurlyCurly.ts, 25, 13))
}

View File

@ -0,0 +1,74 @@
=== tests/cases/compiler/genericWithNoConstraintComparableWithCurlyCurly.ts ===
function foo<T>() {
>foo : <T>() => void
let x = {};
>x : {}
>{} : {}
x as T;
>x as T : T
>x : {}
}
function bar<T extends unknown>() {
>bar : <T extends unknown>() => void
let x = {};
>x : {}
>{} : {}
x as T;
>x as T : T
>x : {}
}
function baz<T extends {}>() {
>baz : <T extends {}>() => void
let x = {};
>x : {}
>{} : {}
x as T;
>x as T : T
>x : {}
}
function bat<T extends object>() {
>bat : <T extends object>() => void
let x = {};
>x : {}
>{} : {}
x as T;
>x as T : T
>x : {}
}
function no<T extends null | undefined>() {
>no : <T extends null | undefined>() => void
>null : null
let x = {};
>x : {}
>{} : {}
x as T; // should error
>x as T : T
>x : {}
}
function yes<T extends object | null | undefined>() {
>yes : <T extends object | null | undefined>() => void
>null : null
let x = {};
>x : {}
>{} : {}
x as T;
>x as T : T
>x : {}
}

View File

@ -59,11 +59,11 @@ function f4<T>(x: T & 1 | T & 2) {
case 1: x; break; // T & 1
>1 : 1
>x : T & 1
>x : (T & 1) | (T & 2)
case 2: x; break; // T & 2
>2 : 2
>x : T & 2
>x : (T & 1) | (T & 2)
default: x; // Should narrow to never
>x : never

View File

@ -16,7 +16,6 @@ tests/cases/conformance/types/unknown/unknownType1.ts(112,9): error TS2322: Type
tests/cases/conformance/types/unknown/unknownType1.ts(113,9): error TS2322: Type 'unknown' is not assignable to type '{}'.
tests/cases/conformance/types/unknown/unknownType1.ts(114,9): error TS2322: Type 'unknown' is not assignable to type '{} | null | undefined'.
tests/cases/conformance/types/unknown/unknownType1.ts(120,9): error TS2322: Type 'T' is not assignable to type 'object'.
Type 'unknown' is not assignable to type 'object'.
tests/cases/conformance/types/unknown/unknownType1.ts(128,5): error TS2322: Type 'number[]' is not assignable to type '{ [x: string]: unknown; }'.
Index signature for type 'string' is missing in type 'number[]'.
tests/cases/conformance/types/unknown/unknownType1.ts(129,5): error TS2322: Type 'number' is not assignable to type '{ [x: string]: unknown; }'.
@ -26,9 +25,7 @@ tests/cases/conformance/types/unknown/unknownType1.ts(150,17): error TS2355: A f
tests/cases/conformance/types/unknown/unknownType1.ts(156,14): error TS2700: Rest types may only be created from object types.
tests/cases/conformance/types/unknown/unknownType1.ts(162,5): error TS2564: Property 'a' has no initializer and is not definitely assigned in the constructor.
tests/cases/conformance/types/unknown/unknownType1.ts(171,9): error TS2322: Type 'U' is not assignable to type '{}'.
Type 'unknown' is not assignable to type '{}'.
tests/cases/conformance/types/unknown/unknownType1.ts(181,5): error TS2322: Type 'T' is not assignable to type '{}'.
Type 'unknown' is not assignable to type '{}'.
==== tests/cases/conformance/types/unknown/unknownType1.ts (27 errors) ====
@ -188,7 +185,6 @@ tests/cases/conformance/types/unknown/unknownType1.ts(181,5): error TS2322: Type
let y: object = x; // Error
~
!!! error TS2322: Type 'T' is not assignable to type 'object'.
!!! error TS2322: Type 'unknown' is not assignable to type 'object'.
}
// Anything fresh but primitive assignable to { [x: string]: unknown }
@ -257,7 +253,6 @@ tests/cases/conformance/types/unknown/unknownType1.ts(181,5): error TS2322: Type
let y: {} = u;
~
!!! error TS2322: Type 'U' is not assignable to type '{}'.
!!! error TS2322: Type 'unknown' is not assignable to type '{}'.
}
// Repro from #26796
@ -270,6 +265,5 @@ tests/cases/conformance/types/unknown/unknownType1.ts(181,5): error TS2322: Type
return arg; // Error
~~~~~~~~~~~
!!! error TS2322: Type 'T' is not assignable to type '{}'.
!!! error TS2322: Type 'unknown' is not assignable to type '{}'.
}

View File

@ -44,7 +44,6 @@ tests/cases/conformance/types/tuple/variadicTuples2.ts(73,5): error TS2322: Type
tests/cases/conformance/types/tuple/variadicTuples2.ts(74,5): error TS2322: Type '[number, ...T]' is not assignable to type '[number, ...number[]]'.
Type at position 1 in source is not compatible with type at position 1 in target.
Type 'T[number]' is not assignable to type 'number'.
Type 'unknown' is not assignable to type 'number'.
tests/cases/conformance/types/tuple/variadicTuples2.ts(107,16): error TS2345: Argument of type '[1, 2, 3, 4]' is not assignable to parameter of type '[...number[], (...values: number[]) => void]'.
Type at position 3 in source is not compatible with type at position 1 in target.
Type 'number' is not assignable to type '(...values: number[]) => void'.
@ -206,7 +205,6 @@ tests/cases/conformance/types/tuple/variadicTuples2.ts(130,25): error TS2345: Ar
!!! error TS2322: Type '[number, ...T]' is not assignable to type '[number, ...number[]]'.
!!! error TS2322: Type at position 1 in source is not compatible with type at position 1 in target.
!!! error TS2322: Type 'T[number]' is not assignable to type 'number'.
!!! error TS2322: Type 'unknown' is not assignable to type 'number'.
}
// Inference

View File

@ -0,0 +1,30 @@
// @strict: true
function foo<T>() {
let x = {};
x as T;
}
function bar<T extends unknown>() {
let x = {};
x as T;
}
function baz<T extends {}>() {
let x = {};
x as T;
}
function bat<T extends object>() {
let x = {};
x as T;
}
function no<T extends null | undefined>() {
let x = {};
x as T; // should error
}
function yes<T extends object | null | undefined>() {
let x = {};
x as T;
}