Skip to content

Commit 0ef844f

Browse files
authored
Avoid this-instantiation if not necessary for relationship (#28263)
1 parent 8e4b90d commit 0ef844f

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/compiler/checker.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12065,12 +12065,15 @@ namespace ts {
1206512065
return result;
1206612066
}
1206712067
}
12068-
else {
12069-
const instantiated = getTypeWithThisArgument(constraint, source);
12070-
if (result = isRelatedTo(instantiated, target, reportErrors, /*headMessage*/ undefined, isIntersectionConstituent)) {
12068+
// 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
12069+
else if (result = isRelatedTo(constraint, target, /*reportErrors*/ false, /*headMessage*/ undefined, isIntersectionConstituent)) {
1207112070
errorInfo = saveErrorInfo;
1207212071
return result;
12073-
}
12072+
}
12073+
// slower, fuller, this-instantiated check (necessary when comparing raw `this` types from base classes), see `subclassWithPolymorphicThisIsAssignable.ts` test for example
12074+
else if (result = isRelatedTo(getTypeWithThisArgument(constraint, source), target, reportErrors, /*headMessage*/ undefined, isIntersectionConstituent)) {
12075+
errorInfo = saveErrorInfo;
12076+
return result;
1207412077
}
1207512078
}
1207612079
else if (source.flags & TypeFlags.Index) {

0 commit comments

Comments
 (0)