Hacker News new | ask | show | jobs
by davman 1590 days ago
I'd love to know more about how you're doing enums. We use JSDoc annotated JS code with tsc switched on to get the IDE integration, and I spent a huge chunk of time yesterday getting enums to work so that for example we could define a type where only certain enum values were valid (enum member types https://www.typescriptlang.org/docs/handbook/enums.html#unio... )

Was preparing a blog post on this enum work, but if you've solved it differently it'd be great to know :)

1 comments

My approach is really pragmatic. You're unlikely to mix enums that have nothing to do with each other. The only issue in those enums that you could possibly get mixed up. For those you can just use non-overlapping integers for the values. It also makes debugging easier "over the wire", because you're probably not encoding the enums as strings. There is really no reason to have all enums map to the same handful of integers. If you don't do that, it just works.