@@ -27254,7 +27254,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
2725427254 }
2725527255 // We first attempt to filter the current type, narrowing constituents as appropriate and removing
2725627256 // constituents that are unrelated to the candidate.
27257- const isRelated = checkDerived ? isTypeDerivedFrom : isTypeStrictSubtypeOf ;
27257+ const isRelated = checkDerived ? isTypeDerivedFrom : isTypeSubtypeOf ;
2725827258 const keyPropertyName = type.flags & TypeFlags.Union ? getKeyPropertyName(type as UnionType) : undefined;
2725927259 const narrowedType = mapType(candidate, c => {
2726027260 // If a discriminant property is available, use that to reduce the type.
@@ -27264,7 +27264,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
2726427264 // specific of the two. When t and c are related in both directions, we prefer c for type predicates
2726527265 // because that is the asserted type, but t for `instanceof` because generics aren't reflected in
2726627266 // prototype object types.
27267- const directlyRelated = mapType(matching || type, t => isRelated(t, c) ? t : isRelated(c, t) ? c : neverType);
27267+ const directlyRelated = mapType(matching || type, checkDerived ?
27268+ t => isTypeDerivedFrom(t, c) ? t : isTypeDerivedFrom(c, t) ? c : neverType :
27269+ t => isTypeStrictSubtypeOf(t, c) ? t : isTypeStrictSubtypeOf(c, t) ? c : isTypeSubtypeOf(t, c) ? t : isTypeSubtypeOf(c, t) ? c : neverType);
2726827270 // If no constituents are directly related, create intersections for any generic constituents that
2726927271 // are related by constraint.
2727027272 return directlyRelated.flags & TypeFlags.Never ?
@@ -27274,7 +27276,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
2727427276 // If filtering produced a non-empty type, return that. Otherwise, pick the most specific of the two
2727527277 // based on assignability, or as a last resort produce an intersection.
2727627278 return !(narrowedType.flags & TypeFlags.Never) ? narrowedType :
27277- isTypeStrictSubtypeOf (candidate, type) ? candidate :
27279+ isTypeSubtypeOf (candidate, type) ? candidate :
2727827280 isTypeAssignableTo(type, candidate) ? type :
2727927281 isTypeAssignableTo(candidate, type) ? candidate :
2728027282 getIntersectionType([type, candidate]);
0 commit comments