Skip to content

Commit

Permalink
Avoid this-instantiation if not necessary for relationship (#28263)
Browse files Browse the repository at this point in the history
  • Loading branch information
weswigham committed Oct 31, 2018
1 parent 8e4b90d commit 0ef844f
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12065,12 +12065,15 @@ namespace ts {
return result;
}
}
else {
const instantiated = getTypeWithThisArgument(constraint, source);
if (result = isRelatedTo(instantiated, target, reportErrors, /*headMessage*/ undefined, isIntersectionConstituent)) {
// 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, /*reportErrors*/ false, /*headMessage*/ undefined, isIntersectionConstituent)) {
errorInfo = 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, reportErrors, /*headMessage*/ undefined, isIntersectionConstituent)) {
errorInfo = saveErrorInfo;
return result;
}
}
else if (source.flags & TypeFlags.Index) {
Expand Down

0 comments on commit 0ef844f

Please sign in to comment.