HiveBrain v1.2.0
Get Started
← Back to all entries
patternjavascriptMajor

Using spread syntax and new Set() with typescript

Submitted by: @import:stackoverflow-api··
0
Viewed 0 times
typescriptwithandsyntaxsetusingspreadnew

Problem

I am using following code to get unique numbers:

let uniques = [ ...new Set([1, 2, 3, 1, 1]) ]; // [1, 2, 3]


However, typescript report following error: Type 'Set' is not an array type.
I am not typescript ninja, could someone tell me what is wrong here?

Solution

This is a missing feature. TypeScript only supports iterables on Arrays at the moment.

Context

Stack Overflow Q#33464504, score: 61

Revisions (0)

No revisions yet.