u/derNikoDemin r/typescript • Recommends
On “enum vs "as const" vs Object.freeze() what is the difference between those 3?”
Intermediate. Assumes working knowledge.
256K views3 years ago5 recommendations
Programming languagesTypeScriptLanguage design and type systems
Matt Pocock explains why TypeScript enums have design flaws and why using object constants with as const is a better alternative.
TypeScript enums are not great. In almost all cases, I use an 'as const' with a sprinkling of type magic to express them. Become a TypeScript Wizard with Matt's TypeScript Course: totaltypescript.com/ Follow Matt on Twitter twitter.com/mattpocockukWhat people say. Engineers frequently point to this video to explain why TypeScript enums should be avoided in favor of object constants.
u/derNikoDemin r/typescript • Recommends
On “enum vs "as const" vs Object.freeze() what is the difference between those 3?”
u/Wrexesin r/typescript • Recommends
On “String union type of enum?”
u/Worldly-Froyo4804in r/typescript • Recommends
On “What's the preferred way to create an object of constants and then use it as a type?”
u/Infinitehin r/typescript • Recommends
On “How to get this typing behavior?”
u/phischer_hin r/typescript • Recommends
On “Safer exhaustive switch statements in TypeScript”
u/Infinitehin r/typescript • Recommends
On “Review Request: Which one is better and why?”
u/Wrexesin r/typescript • Mentions
On “Do I put enums in types.ts?”
u/sagabanin r/typescript • Mentions
On “What's the preferred way to create an object of constants and then use it as a type?”