Hacker News new | ask | show | jobs
by lucasyvas 1608 days ago
This is the way, because iterating enums produces odd results due to a bidirectional mapping.

I had always used enums in TS until this year, but union literals are better.

I create my own enums with const objects, compute the type based off the object's values. So very similar this, just with an object as the source instead of an array.

1 comments

Iterating over an enum in TypeScript always felt like code smell to me because of the filtering code I'd have to write to deal with the bidirectional mapping.