Skip to content
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

support destructuring, spread of all iterables, not just arrays #1059

Closed
samwgoldman opened this issue Nov 8, 2015 · 7 comments
Closed

support destructuring, spread of all iterables, not just arrays #1059

samwgoldman opened this issue Nov 8, 2015 · 7 comments

Comments

@samwgoldman
Copy link
Member

const [a, b, c] = new Set([1, 2, 3]);

With the above code, I expect there to be no errors, and each binding a, b, c should be number.

Today, I get the following errors:

test.js:2
 2: const [a, b, c] = new Set([1, 2, 3]);
           ^ element 0. Indexable signature not found in
Set. See: [LIB] core.js:376

test.js:2
 2: const [a, b, c] = new Set([1, 2, 3]);
              ^ element 1. Indexable signature not found in
Set. See: [LIB] core.js:376

test.js:2
 2: const [a, b, c] = new Set([1, 2, 3]);
                 ^ element 2. Indexable signature not found in
Set. See: [LIB] core.js:376

relevant spec text.

@samwgoldman
Copy link
Member Author

It should also be possible to spread arbitrary iterables, not just arrays:

const set = new Set([1, 2, 3]);
console.log(...set); // 1, 2, 3
test.js:2
  2: const set = new Set([1, 2, 3]);
                 ^^^^^^^^^^^^^^^^^^ constructor call
  3: console.log(...set); // 1, 2, 3
                    ^^^ Set. This type is incompatible with
  3: console.log(...set); // 1, 2, 3
                    ^^^ spread operand

@samwgoldman samwgoldman changed the title support array destructuring of all iterables, not just arrays support destructuring, spread of all iterables, not just arrays Nov 8, 2015
@MoOx
Copy link

MoOx commented Jun 2, 2016

Meanwhile, any workarounds to ignore this issue for spread with set?

@jchitel
Copy link

jchitel commented Aug 21, 2016

I'm a few months late, but a workaround is to wrap all iterables (set, map, generator, string, custom iterables) in Array.from before spreading them.

@junosuarez
Copy link

Another example, but DOM NodeList should also be supported:

[...document.querySelectorAll('img')].forEach(node => node.remove())

@facundocabrera
Copy link

Any idea about the roadmap for this improvement?

@calebmer
Copy link
Contributor

It looks like this works now: https://flow.org/try/#0MYewdgzgLgBAHjAvDMBTA7jAyqqAKAbQEYAaGAJjIGYBdASgG4AoUSWATyRgIDo+4azJnnYEADDQBcKAK4BbAEaoATo2GiJ06MoCWYAOZqgA

Let me know if this is still an issue 👍

@skeggse
Copy link
Contributor

skeggse commented May 14, 2020

@calebmer that looks like a particular case of destructuring - it looks like destructuring assignments still don't work: https://flow.org/try/#0PQKhCgAIUgBAzANgewO6QM4BcBOBLAYyyhGHHABMBTAxAQxysgDcGWAuSASSypzoBGiKgB5s+AHYBzAHwBucgWQTskANrw8ObAF1IAXhYKlKrOoB0lxroNHwACk3asncXmkBKBfesvMudyk1HS9wIA

Opened as new ticket #8375

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants