From 76d194440c2586557b73bb15cb40dd9550ff3a0b Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Thu, 20 Oct 2016 09:06:36 -0700 Subject: [PATCH] Spread no longer distributes intersections --- src/compiler/checker.ts | 18 ++++-------------- src/compiler/types.ts | 2 +- 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index e3651f6cf30..f0ad77cd5c4 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5810,11 +5810,6 @@ namespace ts { types.push(rspread.right); return getSpreadType(types, symbol, aliasSymbol, aliasTypeArguments); } - if (right.flags & TypeFlags.Intersection) { - const spreads = map((right as IntersectionType).types, - t => getSpreadType(types.slice().concat([t]), symbol, aliasSymbol, aliasTypeArguments)); - return getIntersectionType(spreads, aliasSymbol, aliasTypeArguments); - } if (right.flags & TypeFlags.Union) { const spreads = map((right as UnionType).types, t => getSpreadType(types.slice().concat([t]), symbol, aliasSymbol, aliasTypeArguments)); @@ -5840,11 +5835,6 @@ namespace ts { const simplified = getSpreadType([right, (left as SpreadType).right], symbol, aliasSymbol, aliasTypeArguments); return getSpreadType([(left as SpreadType).left, simplified], symbol, aliasSymbol, aliasTypeArguments); } - if (left.flags & TypeFlags.Intersection) { - const spreads = map((left as IntersectionType).types, - t => getSpreadType(types.slice().concat([t, right]), symbol, aliasSymbol, aliasTypeArguments)); - return getIntersectionType(spreads, aliasSymbol, aliasTypeArguments); - } if (left.flags & TypeFlags.Union) { const spreads = map((left as UnionType).types, t => getSpreadType(types.slice().concat([t, right]), symbol, aliasSymbol, aliasTypeArguments)); @@ -5901,9 +5891,9 @@ namespace ts { } const spread = spreadTypes[id] = createObjectType(TypeFlags.Spread, symbol) as SpreadType; Debug.assert(!!(left.flags & (TypeFlags.Spread | TypeFlags.ObjectType)), "Left flags: " + left.flags.toString(2)); - Debug.assert(!!(right.flags & (TypeFlags.TypeParameter | TypeFlags.ObjectType)), "Right flags: " + right.flags.toString(2)); + Debug.assert(!!(right.flags & (TypeFlags.TypeParameter | TypeFlags.Intersection | TypeFlags.ObjectType)), "Right flags: " + right.flags.toString(2)); spread.left = left as SpreadType | ResolvedType; - spread.right = right as TypeParameter | ResolvedType; + spread.right = right as TypeParameter | IntersectionType | ResolvedType; spread.aliasSymbol = aliasSymbol; spread.aliasTypeArguments = aliasTypeArguments; return spread; @@ -6953,11 +6943,11 @@ namespace ts { spreadTypeRelatedTo(source.right.flags & TypeFlags.ObjectType ? source.left as SpreadType : source, target.right.flags & TypeFlags.ObjectType ? target.left as SpreadType : target); } - // If both right sides are type parameters, then they must be identical for the spread types to be related. + // If both right sides are type parameters or intersections, then they must be identical for the spread types to be related. // It also means that the left sides are either spread types or object types. // if one left is object and the other is spread, that means the second has another type parameter. which isn't allowed - if (target.right.symbol !== source.right.symbol) { + if (target.right !== source.right) { return false; } if (source.left.flags & TypeFlags.Spread && target.left.flags & TypeFlags.Spread) { diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 10c9abbd1ca..3dbfba72acb 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -2780,7 +2780,7 @@ namespace ts { /* @internal */ export interface SpreadType extends Type { left: SpreadType | ResolvedType; - right: TypeParameter | ResolvedType; + right: TypeParameter | IntersectionType | ResolvedType; } /* @internal */