Gregory Houllier
Gregory Houllier

Reputation: 1327

How to use array literals spread operator in TypeScript

TypeScript seems to not correctly support array literals spread operator.

Array.from example worked const uniq1 = (list: Iterable<any>): Array<any> => Array.from(new Set<any>(list))

Array spread example broken const uniq2 = (list: Iterable<any>): Array<any> => [...new Set<any>(list)]

The second example return the following error: Type 'Set' is not an array type.

Upvotes: 2

Views: 513

Answers (2)

fzzle
fzzle

Reputation: 1494

This is a missing feature. Spreads ... aren't fully implemented yet.

Upvotes: 0

Arkej
Arkej

Reputation: 2251

TypeScript doesn't support spread operator now, but it will change in future:

https://github.com/Microsoft/TypeScript/wiki/Roadmap#21

Upvotes: 2

Related Questions