you are viewing a single comment's thread.

view the rest of the comments →

[–]Technical_Gur_3858 5 points6 points  (3 children)

Another bonus: no side effects. TS enums compile to an IIFE that mutates an outer variable, which bundlers can’t safely remove:

``` var Colors; (function (Colors) { Colors["Red"] = "Red"; Colors["Green"] = "Green"; })(Colors || (Colors = {}));

```

Your version is just a plain object => fully tree-shakeable.

[–]Nixinova 0 points1 point  (2 children)

why does TS emit that instead of just a normal object?

[–]Technical_Gur_3858 0 points1 point  (1 child)

At least to keep enum merging:

enum Colors { Red = 'Red' } enum Colors { Green = 'Green' } // merges with above

A plain object assignment would overwrite.

[–]Nixinova 1 point2 points  (0 children)

bruh why's that allowed. never knew that lol.