1
00:00:00,000 --> 00:00:04,200
Does enum disappear when TypeScript compiles?

2
00:00:04,200 --> 00:00:06,530
I wanted two labels, not a

3
00:00:06,530 --> 00:00:09,160
souvenir shop in my JavaScript.

4
00:00:09,340 --> 00:00:12,400
An enum is an enumeration: named constants.

5
00:00:12,400 --> 00:00:14,360
A normal numeric enum produces an

6
00:00:14,360 --> 00:00:16,200
object with mappings both ways.

7
00:00:16,200 --> 00:00:19,300
Guest becomes zero, and zero maps back to Guest.

8
00:00:19,480 --> 00:00:21,400
Here is the generated JavaScript.

9
00:00:21,400 --> 00:00:24,400
That assignment creates the forward and reverse entries.

10
00:00:24,400 --> 00:00:27,200
String enums do not get the reverse mapping.

11
00:00:27,380 --> 00:00:29,100
If you just need named values,

12
00:00:29,100 --> 00:00:31,200
a plain object with as const works.

13
00:00:31,200 --> 00:00:34,200
The assertion preserves literal types, then disappears.

14
00:00:34,200 --> 00:00:35,860
The object itself stays.

15
00:00:36,040 --> 00:00:38,600
Keep an enum when its runtime behavior fits.

16
00:00:38,600 --> 00:00:41,600
For types only, a union emits nothing.

17
00:00:41,600 --> 00:00:44,680
Check your compiler output; const enum has different rules.

18
00:00:44,860 --> 00:00:47,000
I ordered two labels.

19
00:00:47,000 --> 00:00:50,340
The compiler included a return department.
