-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Comments
If I took your example and later added var [x, a, b]: [, string, number] = [0, "a", 5]; What is the desired behavior? |
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: 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] |
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? |
@zhuravlikjb any thoughts on the above question? |
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. :) |
Doesn't seem to be a lot of desire for this in practice, plus it introduces new weird cases as Daniel pointed out. |
Want to write something like this:
instead of inserting 'any' manually to all the omitted positions.
The text was updated successfully, but these errors were encountered: