Skip to content

Commit ba8ae71

Browse files
committed
Move this check and remove unnecessary symmetry
1 parent 5754edc commit ba8ae71

1 file changed

Lines changed: 9 additions & 15 deletions

File tree

src/compiler/checker.ts

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22145,21 +22145,6 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
2214522145
if (s & TypeFlags.BigIntLike && t & TypeFlags.BigInt) return true;
2214622146
if (s & TypeFlags.BooleanLike && t & TypeFlags.Boolean) return true;
2214722147
if (s & TypeFlags.ESSymbolLike && t & TypeFlags.ESSymbol) return true;
22148-
// For comparable relation, revert `this` type parameters back to their constrained class type
22149-
if (relation === comparableRelation) {
22150-
if (s & TypeFlags.TypeParameter && (source as TypeParameter).isThisType) {
22151-
const constraint = getConstraintOfTypeParameter(source as TypeParameter);
22152-
if (constraint && isTypeRelatedTo(constraint, target, relation)) {
22153-
return true;
22154-
}
22155-
}
22156-
if (t & TypeFlags.TypeParameter && (target as TypeParameter).isThisType) {
22157-
const constraint = getConstraintOfTypeParameter(target as TypeParameter);
22158-
if (constraint && isTypeRelatedTo(source, constraint, relation)) {
22159-
return true;
22160-
}
22161-
}
22162-
}
2216322148
if (
2216422149
s & TypeFlags.Enum && t & TypeFlags.Enum && source.symbol.escapedName === target.symbol.escapedName &&
2216522150
isEnumTypeRelatedTo(source.symbol, target.symbol, errorReporter)
@@ -22213,6 +22198,15 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
2221322198
if (source.flags !== target.flags) return false;
2221422199
if (source.flags & TypeFlags.Singleton) return true;
2221522200
}
22201+
if (relation === comparableRelation) {
22202+
// Allow comparability between 'this' and derived classes
22203+
if (source.flags & TypeFlags.TypeParameter && (source as TypeParameter).isThisType) {
22204+
const constraint = getConstraintOfTypeParameter(source as TypeParameter);
22205+
if (constraint && isTypeRelatedTo(constraint, target, relation)) {
22206+
return true;
22207+
}
22208+
}
22209+
}
2221622210
if (source.flags & TypeFlags.Object && target.flags & TypeFlags.Object) {
2221722211
const related = relation.get(getRelationKey(source, target, IntersectionState.None, relation, /*ignoreConstraints*/ false));
2221822212
if (related !== undefined) {

0 commit comments

Comments
 (0)