Skip to content

Commit

Permalink
Bail early in getNarrowedTypeWorker if type is candidate (#55926)
Browse files Browse the repository at this point in the history
  • Loading branch information
jakebailey authored Nov 6, 2023
1 parent 1ed8ed6 commit 4b29ab5
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28306,6 +28306,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {

function getNarrowedTypeWorker(type: Type, candidate: Type, assumeTrue: boolean, checkDerived: boolean) {
if (!assumeTrue) {
if (type === candidate) {
return neverType;
}
if (checkDerived) {
return filterType(type, t => !isTypeDerivedFrom(t, candidate));
}
Expand All @@ -28315,6 +28318,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
if (type.flags & TypeFlags.AnyOrUnknown) {
return candidate;
}
if (type === candidate) {
return candidate;
}

// We first attempt to filter the current type, narrowing constituents as appropriate and removing
// constituents that are unrelated to the candidate.
const isRelated = checkDerived ? isTypeDerivedFrom : isTypeSubtypeOf;
Expand Down

0 comments on commit 4b29ab5

Please sign in to comment.