Flow: Array destructuring and assignment

Created on 23 Dec 2016  路  5Comments  路  Source: facebook/flow

Hello,

I found an issue with the array destructuring assigment (I checked and I didn't find it in the list):
[res[i], res[j]] = [res[j], res[i]];

returns

unsupported expression pattern in destructuring: /home/...

Thanks for your amazing work by the way :)

destructuring enhancement incompleteness

Most helpful comment

This should also be valid:

const obj: any = {};
const obj2: any = {};
const arr = [1];

[obj.one] = arr;
({one: obj2.one} = obj);

// obj === { one: 1 }
// obj2 === { one: 1 }

but Flow gives an error:

[obj.one] = arr;
    ^ unsupported expression pattern in destructuring
({one: obj2.one} = obj);
           ^ unsupported expression pattern in destructuring

All 5 comments

yes,

let a = [1,2,3]
let i = 0, j = 1;

//[a[i], a[j]] = [a[j], a[i]] // error

let [c, d] = [a[i], a[j]] //ok

This should also be valid:

const obj: any = {};
const obj2: any = {};
const arr = [1];

[obj.one] = arr;
({one: obj2.one} = obj);

// obj === { one: 1 }
// obj2 === { one: 1 }

but Flow gives an error:

[obj.one] = arr;
    ^ unsupported expression pattern in destructuring
({one: obj2.one} = obj);
           ^ unsupported expression pattern in destructuring

@vkurchatkin @calebmer is this issue anywhere on the roadmap?

Would also be very interested in this.

Any news on this one? This is ridiculous.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

STRML picture STRML  路  48Comments

StoneCypher picture StoneCypher  路  253Comments

TylerEich picture TylerEich  路  49Comments

jlongster picture jlongster  路  55Comments

cletusw picture cletusw  路  52Comments