-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Logical Unary Assignment Operators &&= and ||= #31011
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
Comments
Looks like you are talking about logical assignment operators, currently a Stage 1 Proposal for introduction into ECMAScript. TypeScript doesn't generally implement new language features until they reach Stage 3. I think if you want to see movement on this you'd have better luck participating in the ECMAScript proposal process. Cheers! |
@jcalz indeed. I was using the wrong terms and failed to find the proposal. Thanks for the links! |
It would violate goal 8:
|
Duplicate #37255 |
yes but now, it's in stage 3:) --- Update Aug 6th it's in stage 4 right now |
It's in stage 3!!! |
Seems to be different from my proposal though, where a ||= b is equivalent to a = a || b and a &&= b is equivalent to a = a && b |
@RyanCavanaugh do you think this can be reopened? Babel shipped support for it in preset-env a few days ago |
What's the status of this? This is now supported in Firefox, Chrome, and Safari |
Search Terms
Suggestion
Typescript currently supports unary logical operators of the form
x += y
andx -= y
, that are syntactically equivalent tox = x + y
andx = x - y
.I would like to see the introduction of the logical equivalent of these operators, say
&&=
and||=
.Use Cases
Expressions that take the form
x = x && y
andx = x || y
could be expressed more succinctly byx &&= y
andx ||= y
respectively, using the proposed operators.It is often the case that deeply nested properties in an object tree need to be assigned a fallback using the
||
operator. The latter operator, being binary, would require repeating the property drill-down expression.Examples
With the proposed operators, this could be expressed more succinctly as
The operators
&&=
and||=
would hence by syntactic sugar for the binary equivalents&&
and||
where the result of the expressions are assigned to the first operator in the original binart expression. That is:x &&= y
is syntactically equivalent tox = x && y
x ||= y
is syntactically equivalent tox = x || y
All rules for the equivalent expressions using the existing binary operators apply.
Please note that no change is required to existing operators or other language features.
Checklist
My suggestion meets these guidelines:
The text was updated successfully, but these errors were encountered: