-
Notifications
You must be signed in to change notification settings - Fork 90
Unified pattern matching and destructuring syntax #160
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
I like the idea. Does the syntax work out, given all the ASI constraints, etc? How would TypeScript itself adopt it? Doesn't it conflict with TypeScript's own use of (This TypeScript conflict killed infix bang as sugar for the eventual-send proposal.) |
To my knowledge, TypeScript never allows |
This would need to be its own proposal, at which point pattern matching could adopt it - while the potential difference between [[HasOwnProperty]] and |
@ljharb , this could not be in its own proposal. The whole point is to unify syntax to ease learning and maximize likelihood of acceptance. Separating this proposal into a separate proposal would ensure that the pattern matching syntax would not have compatibility with destructuring syntax because of the |
I like the idea, but:
|
@chriskuech a syntax like that absolutely must be its own proposal, because it wouldn't just apply inside pattern matching - it'd have to work everywhere. |
This comment has been minimized.
This comment has been minimized.
The proposal has been updated in #174. If you have any questions about the updated syntax, please file a new issue. |
One of the issues I've observed across various drafts is the confusing overlap between destructuring and pattern matching. A primary difference between destructuring and matching is that destructuring will match a missing value as
undefined
whereas pattern matching should fail.Inspired by TypeScript's non-null assertion operator, I propose introducing a post-fix unary operator
!
in matches that binds the preceding name only if the destructured value is truthy.This would enable syntax for conditional if let expressions.
This same syntax can be used with pattern matching:
The text was updated successfully, but these errors were encountered: