Skip to content

Ability to skip elements in tuple type annotation #2671

Closed

Description

Want to write something like this:

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

instead of inserting 'any' manually to all the omitted positions.

Activity

  1. DanielRosenwasser commented on Apr 8, 2015

    @DanielRosenwasser
    Member

    If I took your example and later added x as in the following:

    var [x, a, b]: [, string, number] = [0, "a", 5];

    What is the desired behavior?

  2. zhuravlikjb commented on Apr 8, 2015

    @zhuravlikjb
    Author

    I suppose that x here should have type of right-hand-side[0], or 'any', if the right-hand-side is absent.

    Exactly the same way as for ordinary type annotations, when they are omitted:
    var x = 0 => x: number
    var x => x: any

    The same in the case of non-destructuring declarations:

    var x: [, string, number] = [0, "a", 5];     // x is [number, string, number]
    var y: [, string, number];  // y is [any, string, number]
  3. RyanCavanaugh commented on Apr 20, 2016

    @RyanCavanaugh
    Member

    We had a question when discussing this issue -- what are the kinds of cases where the inferred type is "not correct" ? In other words, what's the value of writing these annotations vs letting them be inferred?

  4. RyanCavanaugh commented on Jun 13, 2016

    @RyanCavanaugh
    Member

    Anton Lobov (@zhuravlikjb) any thoughts on the above question?

  5. zhuravlikjb commented on Jul 4, 2016

    @zhuravlikjb
    Author

    Sorry for the delay with answer. This question is just about consistency: JavaScript allows empty items and elision in many syntax elements. If it's allowed for array literals, why not to allow it for type annotations? Nothing critical here if the existing behaviour will remain. Just a "why not" thing. :)

  6. added
    DeclinedThe issue was declined as something which matches the TypeScript vision
    and removed on Sep 28, 2016
  7. RyanCavanaugh commented on Sep 28, 2016

    @RyanCavanaugh
    Member

    Doesn't seem to be a lot of desire for this in practice, plus it introduces new weird cases as Daniel pointed out.

  8. 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

    DeclinedThe issue was declined as something which matches the TypeScript visionSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions