-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Proposal: syntax sugar for binary compare expressions #2903
Comments
Hey @tinganho, thanks for the suggestions, however, you'll have to understand that we tend to be somewhat conservative when it comes to syntax. Additionally, I'm not sure that these fall in line with the direction of our language.
Definitely not something we could do, this is already syntactically valid, and part of common patterns.
We'd be reinventing new semantics for
I think this syntax this strays too far from the general direction we want to move in, as well as the direction of JavaScript itself. |
@DanielRosenwasser I missed the valid syntax part. Though these are problems I currently have today(typing the same identifier too many times). |
I think you may consider 'in' operator for range checks, like: if(value in 1..3) or if(value in Enum.something..Enum.somethingElse) or even if(value in Enum.something..Enum.somethingElse, Enum.somethingSpecial) So that you won't have to reinvent new semantics for |
I think I also have seen this syntax somewhere: I think Swift. if(object.property?.subProperty) {} will be the same as: if(object.property && object.property.subProperty) {} |
These are all suggestions that are on the table for ES7 or later, and thus need to be avoided by TypeScript until their semantics are fully understood. For example, the safe navigation operator can't be simply decomposed as written because there are values which are safe to dot off of that are still falsy: var x = { n: "" };
var y = x?.n?.length; // y should be 0, not undefined or "" |
Also, any discussion on that feature should not be continued here, as it's tracked under #16. |
Auto referring to last identifier:
Instead of:
we can have this:
Auto referring to last identifier and operator:
Instead of:
we can have this:
Range comparisons:
for numbers:
for enums:
The text was updated successfully, but these errors were encountered: