-
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
Refactoring to convert && chain to optional chain expression #35018
Comments
maybe a code-mode or babel transform that runs throughout a codebase? |
@Urigo That could be done too, but I think having this granularity is good because it's not strictly the same semantics. |
Also keep in mind that optional chaining returns |
I'm not sure I really follow. Such code would be rather questionable in the first place, no? If you have an |
I could certainly envision a scenario where code was written that depends on short-circuiting on falsy values. We're eternally stuck with Also there's no TypeError because boolean and string are object-coercible. The subsequent property access would just return |
[|foo && foo.bar && foo.bar.baz|] What do the “|” mean? |
@jineshshah36 |
All too eager to start using the ?. syntax I managed to play a trick on myself by converting Just one of the (probably more obvious in hindsight) things a script would have to keep in mind :) |
There's a question of whether or not nullish coalescing ( |
Also, what the supported patterns are:
|
Ahhhh, i have some existed work about this. And I'm happy to port here |
I’m not sure of the viability of going after library refactorings (as opposed to just JS -> TS), but I think one huge win would be if TS could automatically refactor lodash/get usages and/or ramda/pathOr usages. |
Good idea. IMO TypeScript cannot provide that but there's outside tools. |
Are there any existed tools or algorithms to compare expression and judge they are equality? |
It should be possible to convert that chain into the following:
The text was updated successfully, but these errors were encountered: