-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
consider syntax for tuple literals: (['a', 2]) // [string, number] #9217
Comments
would this help?
|
this is stated as a problem that is sought to be solved
meaning that you example only works thank to explicit type declaration which i wish could be avoided
|
Ah..... I misread the question. I am inclined to say |
we have talked about this before, we could not come up with a proposal that works and looks right.. some of the options considered
nothing seemed palatable to be frank. |
why would not this work:
|
this is rather subtle. looking at it i would not guess, and if i did it by mistake i would not be able to see why it is working any differently. |
We did at one point consider the |
my few centes, speaking for myself:
|
FWIW I kind of like @Aleksey-Bykov proposal.
With the proposed
|
In my projects I use something like this:
The usage is very simple and explicit:
|
@ntrrgc this is my current workaround: #9216 (comment) |
I don't like the analogy with the arrow function returning object literal syntax because that syntax itself is kind of a hack to get around an issue with how arrow functions are specified in ECMAScript. That said, it's a useful hack but it has no impact on the type of the object literal, it has an impact on the type and value of the function, and no one writes them in parentheses except to return them from expression bodied arrow functions. |
like it or not:
so it's easier to get along with it than deny |
i disagree with the "better than nothing". i still find this fairly confusing, let a side undiscovered. |
@mhegazy i was talking about of which, better than nothing means there is no better syntax for object literal results in lambdas (aside from the statements), and this is something no one can change anymore, despite being ugly, it works for a lot of people we've seen it, we hated it but we ate it, and it worked out so there is a precedent |
@Aleksey-Bykov I think where the analogy breaks down is that |
@ahejlsberg, I admit, the syntax is not ideal, and what you said is definitely a weak point of the idea, at the same time it has a number of strong points, as far as i can tell, that were also mentioned to my defence: the fact that ([]) and [] currently mean the same is a waste of valuable syntax, because you don't usually see ([]) in the wild, all I am saying is that it might get a better use |
@Aleksey-Bykov I was objecting to the analogy for the exact reasons that @ahejlsberg mentioned. I was not objecting to the work around syntax for returning object literals from expression bodied arrow functions. I think it's a shame that expression bodied arrow functions require a kludge to work with object literals but the syntax could be worse. I'm saying the analogy is flawed. |
After re-reading my comment I realize I could have been clearer. I was indeed saying that it's not great to follow the precedent of a syntax that is a hack in the first place. |
I know about "not playing at the expression level syntax" rule... x = <>[ 1, 'a', true ] // or [ 1, 'a', true ] as <> - type strongifier
x = #[ 1, 'a', true ] // - AFAIK # now is invalid symbol. treat #[ - as a single delimiter
x = [: 1, 'a', true :] // symmetric smiley brackets |
Closing in favor of #10195 |
Problem
There is no way to get a tuple value without explicit type annotation:
Solution
Add new syntax for tuple literals:
related #9216
The text was updated successfully, but these errors were encountered: