@@ -27254,7 +27254,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
27254
27254
}
27255
27255
// We first attempt to filter the current type, narrowing constituents as appropriate and removing
27256
27256
// constituents that are unrelated to the candidate.
27257
- const isRelated = checkDerived ? isTypeDerivedFrom : isTypeStrictSubtypeOf ;
27257
+ const isRelated = checkDerived ? isTypeDerivedFrom : isTypeSubtypeOf ;
27258
27258
const keyPropertyName = type.flags & TypeFlags.Union ? getKeyPropertyName(type as UnionType) : undefined;
27259
27259
const narrowedType = mapType(candidate, c => {
27260
27260
// If a discriminant property is available, use that to reduce the type.
@@ -27264,7 +27264,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
27264
27264
// specific of the two. When t and c are related in both directions, we prefer c for type predicates
27265
27265
// because that is the asserted type, but t for `instanceof` because generics aren't reflected in
27266
27266
// 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);
27268
27270
// If no constituents are directly related, create intersections for any generic constituents that
27269
27271
// are related by constraint.
27270
27272
return directlyRelated.flags & TypeFlags.Never ?
@@ -27274,7 +27276,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
27274
27276
// If filtering produced a non-empty type, return that. Otherwise, pick the most specific of the two
27275
27277
// based on assignability, or as a last resort produce an intersection.
27276
27278
return !(narrowedType.flags & TypeFlags.Never) ? narrowedType :
27277
- isTypeStrictSubtypeOf (candidate, type) ? candidate :
27279
+ isTypeSubtypeOf (candidate, type) ? candidate :
27278
27280
isTypeAssignableTo(type, candidate) ? type :
27279
27281
isTypeAssignableTo(candidate, type) ? candidate :
27280
27282
getIntersectionType([type, candidate]);
0 commit comments