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

Make default type symbol #5

Open
doug-wade opened this issue Jun 11, 2018 · 1 comment
Open

Make default type symbol #5

doug-wade opened this issue Jun 11, 2018 · 1 comment

Comments

@doug-wade
Copy link

As currently proposed, default enums will have equal members. For instance:

enum COLORS {
   RED,
   BLUE
}

enum PLANTS {
   TREE,
   FERN
}

COLORS.RED === PLANTS.TREE // true

In other staticly-typed languages, this backing number is fine, since the type checker prevents these kinds of comparisons, but that is not the case in js. I mostly worry about switch statements -- if you switch on an enum with another enum or a number, it will appear to work. Not so with a symbol, which will always hit the default case.

@robpalme
Copy link

The value of enums for me is to surface API misuse by locking down the set of acceptable values in one definition - one source of truth.

So defaulting to Symbols would aid this use-case, because it prevents equivalent values being invented/duplicated in arbitrary parts of the code base that may get out of sync with the source of truth over time.

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

No branches or pull requests

2 participants