microsoft/TypeScript

Proposal: Declaring an enum restricted by a number,string or boolean set

jbondc opened this issue · 5 comments

Withdrawn

I'm not sure this adds enough value for the complexity it introduces. Are there any other languages that support this kind of feature? It just adds bounds checking to numeric enums but doesn't scale to other enum spaces. We've had requests for string based enums for example which couldn't use this, we use bit flag enums ourselves a lot, and it's not unreasonable to imagine 'illegal' values within a contiguous bound which this wouldn't protect against.

@danquirk About your mention of other languages, made a weird discovery Pascal has 'set types':
http://en.wikipedia.org/wiki/Pascal_(programming_language)#Set_types

Updated the proposal with links. This should be super familiar to @ahejlsberg 😮

@danquirk "a" | "b" | "c" syntax would be insanely helpful for writing .d.ts files (lots of JS libraries use magic strings).

@jbondc Why the withdrawal? This was a good idea.

@Gaelan I'm sure the TS team will come up with something. I've left the link to set types, maybe they will call it collection types or something. When philosophies diverge too much, it's best to part ways.