File tree Expand file tree Collapse file tree 1 file changed +14
-2
lines changed Expand file tree Collapse file tree 1 file changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -5521,8 +5521,20 @@ namespace ts {
5521
5521
// on either side that need to be prioritized. For example, A | B = (A | B) & (C | D) or
5522
5522
// A & B = (A & B) | (C & D).
5523
5523
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)) {
5526
5538
return result;
5527
5539
}
5528
5540
}
You can’t perform that action at this time.
0 commit comments