-
Provide enum (Enumerated type) in JavaScript.
- This pattern is widely used in JavaScript.
-
Provide Abstract Data Type based on enum.
- It is implemented in many languages in different names like "enum variants" (Rust), "Data Constructor" (Haskell) or "tagged union" (TypeScript).
Roadmap, design goal and relationship to the prior proposals #2
Please go to discussion forum for design details!
https://github.com/rwaldron/proposal-enum-definitions https://github.com/rbuckton/proposal-enum
The current proposal doesn't have a detailed design to be compared with. Currently I'm focusing on figuring out the design constraints before any semantics or syntax.
Before the concreate design, we should decide the design constraints first.
- Enum should have support for symbol, number, string and bigint.
- work well with TypeScript.
- work with structs proposal (constraint by @rbuckton and @syg), normal objects and Record & Tuples (for consistency).
- work well with pattern matching proposal.
- Enum is a frozen, non-extensible normal object
- Enum is a Declaration
- Support number, bigint, string, and symbol
- Support bitflag pattern
- Allow duplicated keys
- Hoistable declarations
enum A { Case1 }
enum B extends A { Case2 }
B.Case1
enum A { A = 1, B = "a" }
enum A { B = 1 }
A.B === 1
some API to get the name of 1 === "B"
enum A { ["a" + "b"]: 1 }
enum A { B = expr() }
enum A { A = 0, B }; A.B === 1
enum A {} // valid TypeScript and flow.js today
enum A of symbol {} // valid flow.js today
enum A { B }; typeof A.B === ?
enum A { A, B, C }; for (const [key, value] of A);