Search code examples
arraystypescriptsettypescript1.8

How can I convert a Set to an Array in TypeScript


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

I have tried those following ways, all of them 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'

Solution

  • Fix

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

    More