Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to skip elements in tuple type annotation #2671

Closed
zhuravlikjb opened this issue Apr 8, 2015 · 6 comments
Closed

Ability to skip elements in tuple type annotation #2671

zhuravlikjb opened this issue Apr 8, 2015 · 6 comments
Labels
Declined The issue was declined as something which matches the TypeScript vision Suggestion An idea for TypeScript

Comments

@zhuravlikjb
Copy link

Want to write something like this:

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

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

@mhegazy mhegazy added the Suggestion An idea for TypeScript label Apr 8, 2015
@DanielRosenwasser
Copy link
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?

@zhuravlikjb
Copy link
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]

@mhegazy mhegazy added the In Discussion Not yet reached consensus label Dec 10, 2015
@RyanCavanaugh
Copy link
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?

@RyanCavanaugh
Copy link
Member

@zhuravlikjb any thoughts on the above question?

@zhuravlikjb
Copy link
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. :)

@RyanCavanaugh RyanCavanaugh added Declined The issue was declined as something which matches the TypeScript vision and removed In Discussion Not yet reached consensus labels Sep 28, 2016
@RyanCavanaugh
Copy link
Member

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

@microsoft microsoft locked and limited conversation to collaborators Jun 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Declined The issue was declined as something which matches the TypeScript vision Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

4 participants