-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Array pattern in destructuring assignment do not typecheck correctly when assigned to an object. #733
Comments
I'm not sure that this is really a bug. Destructing works on objects that are iterators. For example, this is valid JavaScript: let [a,b] = {
0:'A',
1:'B',
[Symbol.iterator]: function*(){
yield this['0'];
yield this['1'];
}
};
console.log(a,b); // Outputs "A B" But in your later example, since an object cannot be an array, an error is thrown. |
I see, at least it should be handled as a special case(actually Flow doesn't support this construct) , but IMHO |
Yeah, we should be able to constrain the RHS to be an iterable in array destructuring assignments. |
@samwgoldman This became a more relevant problem since hooks were introduced. I convert tuple api to object and miss some places. |
I ran into this today. The current behavior results in variables that are typed as |
See also #2612 |
Fixed in 80ca16f |
It seems it comes from here.
Maybe in destructuring we should ensure that the type are "compatible"(good english word ?).
The text was updated successfully, but these errors were encountered: