Skip to content

Tuple suffix associated with rest element in a binding pattern #2714

Closed

Description

You could imagine that someone had the following:

var tuple: [string, number] = ["", 0];
var [a, ...b] = tuple;

Right now, a is string, but b is (string | number)[]. This is because the type associated with b is the array of the element type of the incoming array.

But it would be really nice if b was [number], or at least number[]. You should be able to chop off the rest of the elements in the incoming array, and only use those for the type associated with a rest element.

Activity

  1. added
    By DesignDeprecated - use "Working as Intended" or "Design Limitation" instead
    and removed
    SpecIssues related to the TypeScript language specification
    on May 19, 2015
  2. RyanCavanaugh commented on May 19, 2015

    @RyanCavanaugh
    Member

    The idea as I understand it is that any spread operator assumes that "all of the rest of the values" are in the domain of the tuple-specified types.

    e.g.

    var tuple: [string, number] = ["", 0];
    tuple.push(42); // ok
    tuple.push('hello'); // ok
    tuple.push(window); // err
    var [a, ...b] = tuple; // desired: b: Array<string|number>
  3. 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

    By DesignDeprecated - use "Working as Intended" or "Design Limitation" insteadSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions