Skip to content

Commit 7e4532f

Browse files
Never elaborate errors when relating from intersections.
1 parent db67849 commit 7e4532f

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/compiler/checker.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5521,8 +5521,20 @@ namespace ts {
55215521
// on either side that need to be prioritized. For example, A | B = (A | B) & (C | D) or
55225522
// A & B = (A & B) | (C & D).
55235523
if (source.flags & TypeFlags.Intersection) {
5524-
// If target is a union type the following check will report errors so we suppress them here
5525-
if (result = someTypeRelatedToType(<IntersectionType>source, target, reportErrors && !(target.flags & (TypeFlags.Union | TypeFlags.ObjectType)))) {
5524+
// Check to see if any constituents of the intersection are immediately related to the target.
5525+
//
5526+
// Don't report errors though. Checking whether a constituent is related to the source is not actually
5527+
// useful and leads to some confusing error messages. Instead it is better to let the below checks
5528+
// take care of this, or to not elaborate at all. For instance,
5529+
//
5530+
// - For an object type (such as 'C = A & B'), users are usually more interested in structural errors.
5531+
//
5532+
// - For a union type (such as '(A | B) = (C & D)'), it's better to hold onto the whole intersection
5533+
// than to report that 'D' is not assignable to 'A' or 'B'.
5534+
//
5535+
// - For a primitive type or type parameter (such as 'number = A & B') there is no point in
5536+
// breaking the intersection apart.
5537+
if (result = someTypeRelatedToType(<IntersectionType>source, target, /*reportErrors*/ false)) {
55265538
return result;
55275539
}
55285540
}

0 commit comments

Comments
 (0)