Skip to content

Conversation

itayronen
Copy link

@itayronen itayronen commented Aug 20, 2019

Added a typescript unique feature: Enums

Closes #57

Added a typescript unique feature: Enums
Copy link
Owner

@niieani niieani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to also cover const enums before we merge.

You could also mention that this is one of few the places TypeScript deviates from ECMAScript specification, in that this is not just a type annotation, but this affects the emit too (simply stripping out the types isn't enough for TypeScript enums).

@oriSomething
Copy link
Contributor

@niieani I'm not sure, "const enums" should be mentions, because time after time the TS team against using it in every issue arise about them

@oriSomething
Copy link
Contributor

There is missing about enums:

  • Enums are the only nominal types in TS
  • About number enums: They are always mixed with strings (unlike only string enums)
enum E { a, b } = { a: 0, b: 1, 0: "a", 1: "b" };

@itayronen
Copy link
Author

Agree const enum are not something worth covering. Its a bundle size optimization.
Number enums are not always mixes with string values, you can get the enum key by its value (and vice versa).

I'll add the info about the additional emitted code.
With that said, typescript emits more code than just enums, depends on the ES version you target. It might (Im not sure) be the only additional code if you target es7+.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Typescript Enum
4 participants