@@ -25321,14 +25321,16 @@ namespace ts {
25321
25321
// We first attempt to filter the current type, narrowing constituents as appropriate and removing
25322
25322
// constituents that are unrelated to the candidate.
25323
25323
const narrowedType = type.flags & TypeFlags.AnyOrUnknown ? candidate :
25324
- mapType(candidate, c =>
25325
- mapType(type, t =>
25326
- // If t and c are related, pick the most specific of the two. Otherwise, if t is generic
25327
- // and c is possibly related to t, form an intersection. Otherwise, remove the type.
25328
- isRelated(t, c) ? t :
25329
- isRelated(c, t) ? c :
25330
- maybeTypeOfKind(t, TypeFlags.Instantiable) && isRelated(c, getBaseConstraintOfType(t) || unknownType) ? getIntersectionType([t, c]) :
25331
- neverType));
25324
+ mapType(candidate, c => {
25325
+ // For each constituent t in the current type, if t and and c are directly related, pick the most
25326
+ // specific of the two.
25327
+ const directlyRelated = mapType(type, t => isRelated(t, c) ? t : isRelated(c, t) ? c : neverType);
25328
+ // If no constituents are directly related, create intersections for any generic constituents that
25329
+ // are related by constraint.
25330
+ return directlyRelated.flags & TypeFlags.Never ?
25331
+ mapType(type, t => maybeTypeOfKind(t, TypeFlags.Instantiable) && isRelated(c, getBaseConstraintOfType(t) || unknownType) ? getIntersectionType([t, c]) : neverType) :
25332
+ directlyRelated;
25333
+ });
25332
25334
// If filtering produced a non-empty type, return that. Otherwise, pick the most specific of the two
25333
25335
// based on assignability, or as a last resort produce an intersection.
25334
25336
return !(narrowedType.flags & TypeFlags.Never) ? narrowedType :
0 commit comments