Skip to content

Commit 4b29ab5

Browse files
authored
Bail early in getNarrowedTypeWorker if type is candidate (#55926)
1 parent 1ed8ed6 commit 4b29ab5

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/compiler/checker.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28306,6 +28306,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
2830628306

2830728307
function getNarrowedTypeWorker(type: Type, candidate: Type, assumeTrue: boolean, checkDerived: boolean) {
2830828308
if (!assumeTrue) {
28309+
if (type === candidate) {
28310+
return neverType;
28311+
}
2830928312
if (checkDerived) {
2831028313
return filterType(type, t => !isTypeDerivedFrom(t, candidate));
2831128314
}
@@ -28315,6 +28318,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
2831528318
if (type.flags & TypeFlags.AnyOrUnknown) {
2831628319
return candidate;
2831728320
}
28321+
if (type === candidate) {
28322+
return candidate;
28323+
}
28324+
2831828325
// We first attempt to filter the current type, narrowing constituents as appropriate and removing
2831928326
// constituents that are unrelated to the candidate.
2832028327
const isRelated = checkDerived ? isTypeDerivedFrom : isTypeSubtypeOf;

0 commit comments

Comments
 (0)