Skip to content

Commit f2d739f

Browse files
committed
Spread types handle nested index [access] types
Nested index [access] types are treated as assignable to themselves only, just like type parameters.
1 parent 2ae6ecc commit f2d739f

2 files changed

Lines changed: 5 additions & 4 deletions

File tree

src/compiler/checker.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6097,10 +6097,10 @@ namespace ts {
60976097
}
60986098
const spread = spreadTypes[id] = createType(TypeFlags.Spread) as SpreadType;
60996099
Debug.assert(!!(left.flags & (TypeFlags.Spread | TypeFlags.Object)), "Left flags: " + left.flags.toString(2));
6100-
Debug.assert(!!(right.flags & (TypeFlags.TypeParameter | TypeFlags.Intersection | TypeFlags.Object)), "Right flags: " + right.flags.toString(2));
6100+
Debug.assert(!!(right.flags & (TypeFlags.TypeParameter | TypeFlags.Intersection | TypeFlags.Index | TypeFlags.IndexedAccess | TypeFlags.Object)), "Right flags: " + right.flags.toString(2));
61016101
spread.symbol = symbol;
61026102
spread.left = left as SpreadType | ResolvedType;
6103-
spread.right = right as TypeParameter | IntersectionType | ResolvedType;
6103+
spread.right = right as TypeParameter | IntersectionType | IndexType | IndexedAccessType | ResolvedType;
61046104
spread.aliasSymbol = aliasSymbol;
61056105
spread.aliasTypeArguments = aliasTypeArguments;
61066106
return spread;
@@ -7173,7 +7173,8 @@ namespace ts {
71737173
spreadTypeRelatedTo(source.right.flags & TypeFlags.Object ? source.left as SpreadType : source,
71747174
target.right.flags & TypeFlags.Object ? target.left as SpreadType : target);
71757175
}
7176-
// If both right sides are type parameters or intersections, then they must be identical for the spread types to be related.
7176+
// If both right sides are type parameters, intersections, index types or indexed access types,
7177+
// then they must be identical for the spread types to be related.
71777178
// It also means that the left sides are either spread types or object types.
71787179

71797180
// if one left is object and the other is spread, that means the second has another type parameter. which isn't allowed

src/compiler/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2852,7 +2852,7 @@ namespace ts {
28522852
/* @internal */
28532853
export interface SpreadType extends Type {
28542854
left: SpreadType | ResolvedType;
2855-
right: TypeParameter | IntersectionType | ResolvedType;
2855+
right: TypeParameter | IntersectionType | IndexType | IndexedAccessType | ResolvedType;
28562856
}
28572857

28582858
/* @internal */

0 commit comments

Comments
 (0)