Hacker News new | ask | show | jobs
by forty 478 days ago
That precisely one of my problem with enum: almost all TS type is structural typing, why have this exception enums being nominal typing?
2 comments

Classes aren't interchangable, excepting using a child when a parent is called for.

Likewise, enums represent a discrete and unique set. The fact that there is either a number or a string used under the hood is irrelevant.

I imagine using numbers or strings was useful for interop with vanilla JS (where JS needs to call a TS function with an enum as an argument), so it makes sense to use it instead of Symbols, which is what I typically pretend enumd are.

And to add to the confusion Template Types let you compare enums as if they were strings.