diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 58d6a8b867e20..8e5a04d629c7f 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -28154,6 +28154,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)); } @@ -28163,6 +28166,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;