after the release of typescript 0.9: are listed:
enum Select { every, first, last }
original question:
Enumerations in typescript were discussed here, but no solution led to the creation of an ambient design. The definition of enum enum will mean that the enumeration is processed only by the compiler, and the compiled output js files only process unprocessed numeric values. Like in C ++ 11.
The closest I get
declare var Color = { red: 1, blue: 2, green: 3 }
but the compiler does not accept this: "An environment variable cannot have an initializer."
change
including dmck answer:
declare var Color: { Red: number; Green: number; Blue: number; };
This does not output js code. In other words, it's ambient. However, this makes it useless:
declare var Color: { Red: number; Green: number; Blue: number; }; function test() { var x = Color.Blue;
will result in a runtime error since the color is not defined in js. The ts declaration simply states that there is some Color object in js, but in fact there is no definition. Ti fix it we can add
var Color = { Red: 1, Green: 2, Blue: 3 };
but now the enum implementation is not "ambient" in the sense that the typescript compiler does what the C ++ compiler does, reducing the enumeration values to prime numbers in all cases. Current ambient ads let you check the type, but not such a replacement.