DEV Community

Discussion on: 15 Killer πŸ—‘ JS techniques you've probably never heard of πŸ”ˆπŸ”₯

Collapse
 
ironcladdev profile image
Conner Ow

The spread operator doesn't work with typescript and Set since the type it returns isn't an array, so that's why I did that in this post.

If you're not using ts, the spread operator can absolutely be used.

Collapse
 
jonrandy profile image
Jon Randy πŸŽ–οΈ

Thank god I don't use TS.

The spread syntax is for spreading any iterable - which a Set very definitely is. It is useful for way more than just Arrays or Strings - which TS seems to insist it be one of.

Thread Thread
 
m4heshd profile image
Mahesh Bandara Wijerathna

High five πŸ–πŸ½. I'm one of the rare ones who avoid TS at all costs. No need to make our lives harder as devs just to get on the bandwagon.

Collapse
 
nielsabildgaard profile image
Niels Abildgaard

That's not true, here is a running example of just that: typescriptlang.org/play?#code/MYew...

Thread Thread
 
jonrandy profile image
Jon Randy πŸŽ–οΈ

Not a fan of TS, but is this a recent addition? I tried a TS repl (replit.com/languages/typescript) and got this:

TS error

Thread Thread
 
nielsabildgaard profile image
Niels Abildgaard

Huh, interesting. TIL!