Skip to content

Spread arrays #237

Closed
Closed
@RyanCavanaugh

Description

@RyanCavanaugh

Example from ES6

[1, 2, ...items, 3, ...moreItems]

Type checking

The type of the array is the best common type of the individual elements and the element types of each of the "spread" elements.

Codegen

[1, 2, ...items, 3, ...moreItems]

becomes:

[1,2].concat(items, [3], moreItems)

If the array starts with a spread, you can concat off the spread:

[...items, 1, 2, ...moreItems]

becomes:

items.concat([1, 2], moreItems)

Questions

What if it's 'any'?  We don't know, so we have to codegen a slice. One possible issue is that .concat doesn't take array-like, it takes arrays only.  This won't be a problem for spread arguments because .apply should take array-likes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    CommittedThe team has roadmapped this issueES6Relates to the ES6 SpecFixedA PR has been merged for this issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions