Skip to content

Spread arrays #237

Closed
Closed

Description

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.

Activity

  1. Arnavion commented on Dec 18, 2014

    @Arnavion
    Contributor

    Fixed by #1463 ?

  2. added
    CommittedThe team has roadmapped this issue
    FixedA PR has been merged for this issue
    and removed
    Needs More InfoThe issue still hasn't been fully clarified
    SuggestionAn idea for TypeScript
    on Dec 30, 2014
  3. RyanCavanaugh commented on Dec 30, 2014

    @RyanCavanaugh
    MemberAuthor

    Indeed!

  4. locked and limited conversation to collaborators on Jun 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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