@@ -8457,9 +8457,11 @@ namespace ts {
8457
8457
}
8458
8458
i--;
8459
8459
}
8460
- if (intersection ! == unionType.types) {
8461
- types[unionIndex] = getUnionTypeFromSortedList(intersection, unionType.flags & TypeFlags.UnionOfUnitTypes) ;
8460
+ if (intersection = == unionType.types) {
8461
+ return false ;
8462
8462
}
8463
+ types[unionIndex] = getUnionTypeFromSortedList(intersection, unionType.flags & TypeFlags.UnionOfUnitTypes);
8464
+ return true;
8463
8465
}
8464
8466
8465
8467
// We normalize combinations of intersection and union types based on the distributive property of the '&'
@@ -8489,16 +8491,19 @@ namespace ts {
8489
8491
includes & TypeFlags.ESSymbol && includes & TypeFlags.UniqueESSymbol) {
8490
8492
removeRedundantPrimitiveTypes(typeSet, includes);
8491
8493
}
8492
- if (includes & TypeFlags.UnionOfUnitTypes) {
8493
- intersectUnionsOfUnitTypes(typeSet);
8494
- }
8495
8494
if (includes & TypeFlags.EmptyObject && !(includes & TypeFlags.Object)) {
8496
8495
typeSet.push(emptyObjectType);
8497
8496
}
8498
8497
if (typeSet.length === 1) {
8499
8498
return typeSet[0];
8500
8499
}
8501
8500
if (includes & TypeFlags.Union) {
8501
+ if (includes & TypeFlags.UnionOfUnitTypes && intersectUnionsOfUnitTypes(typeSet)) {
8502
+ // When the intersection creates a reduced set (which might mean that *all* union types have
8503
+ // disappeared), we restart the operation to get a new set of combined flags. Once we have
8504
+ // reduced we'll never reduce again, so this occurs at most once.
8505
+ return getIntersectionType(typeSet, aliasSymbol, aliasTypeArguments);
8506
+ }
8502
8507
// We are attempting to construct a type of the form X & (A | B) & Y. Transform this into a type of
8503
8508
// the form X & A & Y | X & B & Y and recursively reduce until no union type constituents remain.
8504
8509
const unionIndex = findIndex(typeSet, t => (t.flags & TypeFlags.Union) !== 0);
0 commit comments