-
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
Destructuring Type Syntax Sugar #13471
Comments
Please see #7576 (comment). TS is intended to be a super-set of JS; this entails following the ECMAScript spec, and also not introducing new syntax that may conflict with future ECMAScript direction. Moreover, the main issue here is that the use of colon to rename properties goes across how type annotations are specified in TS; so the main issue is discoverablity and intuition, and for that i do not think the I personally do not like the destructuring syntax, and believe |
I don't think I buy discoverability as an argument. It has never really been my experience that I can expect to just start typing new syntax and it just does exactly what I wanted. The current syntax is a perfect example of this, as I recall spending at least 15 minutes trying to figure out why I think Tacking |
You didn't address his main issue, being that The current syntax looks like you are annotating vanilla JS, which is exactly what you're doing. The syntax you propose looks confusing and unclear. Even if I figure out a rename is going on, is the first one the original name? The second one? Actually, looking at the example right now, I'm not even sure. I assume the first one, looking at the other example? |
@mavericken
I had the exact same experience, and I reckon many others did as well. That in itself is a very good reason not to use |
I am adverse to just accepting that there is nothing we can do about it, though. The That being said, the idea has at least gotten the light I thought it deserved, even if not the support... Assuming no support arrives, I'll give an opportunity for any last words and then close. |
@mavericken const { id: name is string } = o; But that could probably clash as well. |
Why isn't |
Suggestion:
|
Destructuring still leaves much to be desired when it forces a lot of unnecessary repetition.
The best idea I saw is actually in the original issue for tracking destructuring:
#240
I feel that idea has mostly been overlooked and now forever sits in a closed issue, and that it deserves a second look.
@fdecampredon commented on Oct 20, 2014
I saw some related issues, but with not as good of syntax proposals. I include them for linking and reference:
#10079
#7576
The text was updated successfully, but these errors were encountered: