From dd55797329ae9349fc4b8e01231e855e61c64be1 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Wed, 31 Oct 2018 12:36:46 -0700 Subject: [PATCH] Avoid this-instantiation if not necessary for relationship --- src/compiler/checker.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 0a6cec7f6cb7e..169d4c9b64e8e 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -12044,12 +12044,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) {