Hacker News new | ask | show | jobs
by Arnavion 1611 days ago
>one of which is a real array that's allocated at runtime.

To be clear, the enum is also defined at runtime. So this specifically isn't a difference.

1 comments

Yes, I didn't intend to imply otherwise, but I could've elaborated.

Some people will argue a preference for string literal union types over enums because the string literal types don't have any runtime overhead. They just provide type safety at write-time and are bare strings at runtime. But as soon as you start adding arrays and custom type predicate functions to work with them, you're adding runtime objects, which removes that particular advantage over enums.