Skip to content

Commit d6d1533

Browse files
committed
Tweak algorithm
1 parent fc81aff commit d6d1533

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/compiler/checker.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25321,14 +25321,16 @@ namespace ts {
2532125321
// We first attempt to filter the current type, narrowing constituents as appropriate and removing
2532225322
// constituents that are unrelated to the candidate.
2532325323
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+
});
2533225334
// If filtering produced a non-empty type, return that. Otherwise, pick the most specific of the two
2533325335
// based on assignability, or as a last resort produce an intersection.
2533425336
return !(narrowedType.flags & TypeFlags.Never) ? narrowedType :

0 commit comments

Comments
 (0)