

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Still calibrating
click for more info
Not enough gems
Cost: 6 gems
1: Enums
incomplete
2: String Enums
incomplete
3: Enum Compilation
incomplete
4: Const Enums
incomplete
5: Enums vs. Union Types
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
Click to play video
If you've been paying attention, you might be wondering "Why would I ever do this":
enum CardSuit {
Hearts = "Hearts",
Diamonds = "Diamonds",
Clubs = "Clubs",
Spades = "Spades",
}
When you could do this:
type CardSuit = "Hearts" | "Diamonds" | "Clubs" | "Spades";
CardSuit.Hearts provides more context than just "Hearts". That said, any good editor is going to say type CardSuit on hover, so it's not a huge win.Personally, I use unions over enums pretty much every time. In fact, Anders Hejlsberg (the creator of TypeScript) has said that they might not even add enums to TypeScript if they were starting over.
You've decided to refactor some of Support.ai's old API pricing code.