proposal-enum icon indicating copy to clipboard operation
proposal-enum copied to clipboard

Make default type symbol

Open doug-wade opened this issue 7 years ago • 1 comments

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.

doug-wade avatar Jun 11 '18 17:06 doug-wade

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.

robpalme avatar Jan 28 '19 08:01 robpalme