From f2d739ffcfef63b738bf6d71eb9e9d8b552cb71b Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Wed, 2 Nov 2016 11:36:25 -0700 Subject: [PATCH] Spread types handle nested index [access] types Nested index [access] types are treated as assignable to themselves only, just like type parameters. --- src/compiler/checker.ts | 7 ++++--- src/compiler/types.ts | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 53d38c1892f..5447e652f08 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -6097,10 +6097,10 @@ namespace ts { } const spread = spreadTypes[id] = createType(TypeFlags.Spread) as SpreadType; Debug.assert(!!(left.flags & (TypeFlags.Spread | TypeFlags.Object)), "Left flags: " + left.flags.toString(2)); - Debug.assert(!!(right.flags & (TypeFlags.TypeParameter | TypeFlags.Intersection | TypeFlags.Object)), "Right flags: " + right.flags.toString(2)); + Debug.assert(!!(right.flags & (TypeFlags.TypeParameter | TypeFlags.Intersection | TypeFlags.Index | TypeFlags.IndexedAccess | TypeFlags.Object)), "Right flags: " + right.flags.toString(2)); spread.symbol = symbol; spread.left = left as SpreadType | ResolvedType; - spread.right = right as TypeParameter | IntersectionType | ResolvedType; + spread.right = right as TypeParameter | IntersectionType | IndexType | IndexedAccessType | ResolvedType; spread.aliasSymbol = aliasSymbol; spread.aliasTypeArguments = aliasTypeArguments; return spread; @@ -7173,7 +7173,8 @@ namespace ts { spreadTypeRelatedTo(source.right.flags & TypeFlags.Object ? source.left as SpreadType : source, target.right.flags & TypeFlags.Object ? target.left as SpreadType : target); } - // If both right sides are type parameters or intersections, then they must be identical for the spread types to be related. + // If both right sides are type parameters, intersections, index types or indexed access types, + // 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 diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 73d1c6d1ed9..ba5e6b2db99 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -2852,7 +2852,7 @@ namespace ts { /* @internal */ export interface SpreadType extends Type { left: SpreadType | ResolvedType; - right: TypeParameter | IntersectionType | ResolvedType; + right: TypeParameter | IntersectionType | IndexType | IndexedAccessType | ResolvedType; } /* @internal */