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?
I think you didn't set the target properly. Try --target ES6
.
Ok, thanks @SaschaNaz
tsconfig.json
{
"compilerOptions": {
"target": "es6",
}
}
thank you @saschanaz
Most helpful comment
I think you didn't set the target properly. Try
--target ES6
.