this post was submitted on 10 Oct 2023
7 points (88.9% liked)

TypeScript

820 readers
1 users here now

founded 1 year ago
MODERATORS
 

I have googled this and even got to the second page, and there does not seem to be any kind of consensus.

As far as I can tell, it's a bad idea because it creates code you don't see and accepts inputs that you wouldn't want. And yet, many people seem to like them more than, say, const unions due to being easier to refactor in bulk.

So what gives? Is this a case of IT people having very strong opinions on stuff that doesn't matter? Or is there a technical reason for or against it?

you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 1 points 8 months ago (1 children)

You probably don't ever need enums since the const keyword was added after enums and const objects handle enum use cases unions don't.

[–] [email protected] 1 points 8 months ago (1 children)

You mean const assertions. Well, the thing is that const assertions are not enums. They don't handle enum use cases in any way.

[–] [email protected] 1 points 8 months ago

I'm talking about if you want an object syntax for accessing constant types to act as an enum https://www.typescriptlang.org/docs/handbook/enums.html#objects-vs-enums