How to convert Set to an array in TypeScript

How can I convert Set (for example, {2,4,6}) in Array [2, 4, 6] to TypeScript without writing a loop explicitly?

I tried the following methods, they all work in JavaScript, but none of them work on TypeScript

[...set] // ERR: "Type 'Set<{}>' is not an array type" in typescript Array.from(set) // ERR: Property 'from' does not exist on type 'ArrayConstructor' 
+7
arrays set typescript
source share
2 answers

Fix

  • Use tsconfig.json with "lib": ["es6"]

More details

+10
source share

You can also do

 Array.from(MySet.values()); 
+4
source share

All Articles