Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typescript Enums #60

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Typescript Enums #60

wants to merge 5 commits into from

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).

README.md Outdated Show resolved Hide resolved
@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+.

README.md Outdated Show resolved Hide resolved
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