From ba8ae71998697cf9750563e5bd21a7dbe05cecf2 Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Tue, 15 Jul 2025 09:20:17 -0700 Subject: [PATCH] Move this check and remove unnecessary symmetry --- src/compiler/checker.ts | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index df88c496070..6292f415009 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -22145,21 +22145,6 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { if (s & TypeFlags.BigIntLike && t & TypeFlags.BigInt) return true; if (s & TypeFlags.BooleanLike && t & TypeFlags.Boolean) return true; if (s & TypeFlags.ESSymbolLike && t & TypeFlags.ESSymbol) return true; - // For comparable relation, revert `this` type parameters back to their constrained class type - if (relation === comparableRelation) { - if (s & TypeFlags.TypeParameter && (source as TypeParameter).isThisType) { - const constraint = getConstraintOfTypeParameter(source as TypeParameter); - if (constraint && isTypeRelatedTo(constraint, target, relation)) { - return true; - } - } - if (t & TypeFlags.TypeParameter && (target as TypeParameter).isThisType) { - const constraint = getConstraintOfTypeParameter(target as TypeParameter); - if (constraint && isTypeRelatedTo(source, constraint, relation)) { - return true; - } - } - } if ( s & TypeFlags.Enum && t & TypeFlags.Enum && source.symbol.escapedName === target.symbol.escapedName && isEnumTypeRelatedTo(source.symbol, target.symbol, errorReporter) @@ -22213,6 +22198,15 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { if (source.flags !== target.flags) return false; if (source.flags & TypeFlags.Singleton) return true; } + if (relation === comparableRelation) { + // Allow comparability between 'this' and derived classes + if (source.flags & TypeFlags.TypeParameter && (source as TypeParameter).isThisType) { + const constraint = getConstraintOfTypeParameter(source as TypeParameter); + if (constraint && isTypeRelatedTo(constraint, target, relation)) { + return true; + } + } + } if (source.flags & TypeFlags.Object && target.flags & TypeFlags.Object) { const related = relation.get(getRelationKey(source, target, IntersectionState.None, relation, /*ignoreConstraints*/ false)); if (related !== undefined) {