Skip to content

Commit 76d1944

Browse files
committed
Spread no longer distributes intersections
1 parent ad10ec5 commit 76d1944

2 files changed

Lines changed: 5 additions & 15 deletions

File tree

src/compiler/checker.ts

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5810,11 +5810,6 @@ namespace ts {
58105810
types.push(rspread.right);
58115811
return getSpreadType(types, symbol, aliasSymbol, aliasTypeArguments);
58125812
}
5813-
if (right.flags & TypeFlags.Intersection) {
5814-
const spreads = map((right as IntersectionType).types,
5815-
t => getSpreadType(types.slice().concat([t]), symbol, aliasSymbol, aliasTypeArguments));
5816-
return getIntersectionType(spreads, aliasSymbol, aliasTypeArguments);
5817-
}
58185813
if (right.flags & TypeFlags.Union) {
58195814
const spreads = map((right as UnionType).types,
58205815
t => getSpreadType(types.slice().concat([t]), symbol, aliasSymbol, aliasTypeArguments));
@@ -5840,11 +5835,6 @@ namespace ts {
58405835
const simplified = getSpreadType([right, (left as SpreadType).right], symbol, aliasSymbol, aliasTypeArguments);
58415836
return getSpreadType([(left as SpreadType).left, simplified], symbol, aliasSymbol, aliasTypeArguments);
58425837
}
5843-
if (left.flags & TypeFlags.Intersection) {
5844-
const spreads = map((left as IntersectionType).types,
5845-
t => getSpreadType(types.slice().concat([t, right]), symbol, aliasSymbol, aliasTypeArguments));
5846-
return getIntersectionType(spreads, aliasSymbol, aliasTypeArguments);
5847-
}
58485838
if (left.flags & TypeFlags.Union) {
58495839
const spreads = map((left as UnionType).types,
58505840
t => getSpreadType(types.slice().concat([t, right]), symbol, aliasSymbol, aliasTypeArguments));
@@ -5901,9 +5891,9 @@ namespace ts {
59015891
}
59025892
const spread = spreadTypes[id] = createObjectType(TypeFlags.Spread, symbol) as SpreadType;
59035893
Debug.assert(!!(left.flags & (TypeFlags.Spread | TypeFlags.ObjectType)), "Left flags: " + left.flags.toString(2));
5904-
Debug.assert(!!(right.flags & (TypeFlags.TypeParameter | TypeFlags.ObjectType)), "Right flags: " + right.flags.toString(2));
5894+
Debug.assert(!!(right.flags & (TypeFlags.TypeParameter | TypeFlags.Intersection | TypeFlags.ObjectType)), "Right flags: " + right.flags.toString(2));
59055895
spread.left = left as SpreadType | ResolvedType;
5906-
spread.right = right as TypeParameter | ResolvedType;
5896+
spread.right = right as TypeParameter | IntersectionType | ResolvedType;
59075897
spread.aliasSymbol = aliasSymbol;
59085898
spread.aliasTypeArguments = aliasTypeArguments;
59095899
return spread;
@@ -6953,11 +6943,11 @@ namespace ts {
69536943
spreadTypeRelatedTo(source.right.flags & TypeFlags.ObjectType ? source.left as SpreadType : source,
69546944
target.right.flags & TypeFlags.ObjectType ? target.left as SpreadType : target);
69556945
}
6956-
// If both right sides are type parameters, then they must be identical for the spread types to be related.
6946+
// If both right sides are type parameters or intersections, then they must be identical for the spread types to be related.
69576947
// It also means that the left sides are either spread types or object types.
69586948

69596949
// if one left is object and the other is spread, that means the second has another type parameter. which isn't allowed
6960-
if (target.right.symbol !== source.right.symbol) {
6950+
if (target.right !== source.right) {
69616951
return false;
69626952
}
69636953
if (source.left.flags & TypeFlags.Spread && target.left.flags & TypeFlags.Spread) {

src/compiler/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2780,7 +2780,7 @@ namespace ts {
27802780
/* @internal */
27812781
export interface SpreadType extends Type {
27822782
left: SpreadType | ResolvedType;
2783-
right: TypeParameter | ResolvedType;
2783+
right: TypeParameter | IntersectionType | ResolvedType;
27842784
}
27852785

27862786
/* @internal */

0 commit comments

Comments
 (0)