-
Notifications
You must be signed in to change notification settings - Fork 89
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
Disallow { a } #325
Comments
That shouldn't be required. |
@tabatkins it's in the spec as a not-consensused-yet feature. I identified them as footguns and therefore included them in the spec. |
I'm confused, what else would |
It means collecting rest properties in the destructing and binding it to a variable out of pattern matching. Developers might think it has the same meaning inside pattern matching. const { x, ...rest } = obj
if (obj2 is { y, ...rest2 }) {
// ?? y and rest2 are not bindings!!
} |
How is that different from any other object destructuring pattern? |
In my example, x and rest is a binding, but y and rest2 is not. |
Yes, I agree this is a difference between destructuring and pattern matching - it has nothing to do with rest properties or with the concise form, though. If we don't want that discrepancy, we'd need to revert to our previous version that had |
Yeah, It would be fairly bad to change this, imo. |
Current spec does not allow
{ ...a }
.You have to write
{ ...let a }
(bind rest toa
) or{ ...(a) }
(test rest with a, where a might be a custom matcher) depends on your intension.I think we should also do this to
{ a, b: 1 }
to disambiguate{ a: a, b: 1 }
(match with a) with{ b: 1} and has "a"
(hasa
property in it).Currently,
{ a }
meansand has "a"
.Or we can do the other way, allowing
{ ...a }
to be{ ...(a) }
.The text was updated successfully, but these errors were encountered: