Hacker News new | past | comments | ask | show | jobs | submit
Had a quick look but I was surprised to see using a Set.

Personally I use a plain string union. If I need to lookup a value based on that I’ll usually create a record (which is just a stricter object). Typescript will error if I tried to add a duplicate.

This is all enforced at build time, whereas using a Set only happens at runtime.

    type Fruit = ‘apple’ | ‘banana’;

    const lookup: Record<Fruit, string> = { ‘apple’: ‘OK’, ‘banana’: ‘Meh’ }
Unions are a more more universal syntax than enums.

It isn’t forced to be a 1:1 map of string to string; I’ll often use string to React components which is really nice for lots of conditional rendering.

On a slightly related topic, I also feel that the ‘type’ keyword is far more useful and preferable than ‘interface’. [1]

[1]: https://www.lloydatkinson.net/posts/2023/favour-typescript-t...

loading story #42771500