Typescript: Set is not an array type

Created on 24 Oct 2015  路  3Comments  路  Source: microsoft/TypeScript

With Babel, I can use spread syntax on a Set. For example, the following neat trick returns the unique elements in an array:

const a = [ 0, 1, 2, 3, 2, 1, 0];
console.log([...new Set(a)]);

// outputs [0, 1, 2, 3]

However in Typescript, I get the following error: Set is not an array type. I presume this is a problem with the lib.d.ts typings?

BTW, I also tried this on http://www.typescriptlang.org/Playground, but there I got the error: "Cannot find the name 'Set'".
Is the Playground not up to date with the latest tsc version?

Question

Most helpful comment

I think you didn't set the target properly. Try --target ES6.

All 3 comments

I think you didn't set the target properly. Try --target ES6.

Ok, thanks @SaschaNaz

tsconfig.json
{ "compilerOptions": { "target": "es6", } }
thank you @saschanaz

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bgrieder picture bgrieder  路  3Comments

kyasbal-1994 picture kyasbal-1994  路  3Comments

Zlatkovsky picture Zlatkovsky  路  3Comments

MartynasZilinskas picture MartynasZilinskas  路  3Comments

siddjain picture siddjain  路  3Comments