title: Is there a way to create enums in typescript that are ambient?
body: <p>edit after release of typescript 0.9: <strong>enums are now supported:</strong></p>
  
  <pre><code>enum Select { every, first, last }
  </code></pre>
  
  <p>original question:</p>
  
  <p>Enums in typescript were discussed here but no solution leads to an ambient design. An ambient enum definition would mean that the enum is handled by the compiler only and the compiled js output files only deal with the raw numerical values. Like in C++11.</p>
  
  <p>The closest I get is</p>
  
  <pre><code>declare var Color = { red: 1, blue: 2, green: 3 } // DOES NOT COMPILE
  </code></pre>
  
  <p>but the compiler does not accept this: "Ambient variable cannot have initializer".</p>
  
  <p><strong>edit</strong><br>
  incorporating dmck's answer:</p>
  
  <pre><code>declare var Color: { Red: number; Green: number; Blue: number; };
  </code></pre>
  
  <p>This does not output any js code. In other words, it is ambient. This however makes it useless as well:</p>
  
  <pre><code>declare var Color: { Red: number; Green: number; Blue: number; };
  
  function test() {
    var x = Color.Blue;    // null ref exception, no Color object
    console.log(x == Color.Red);
  }
  </code></pre>
  
  <p>will produce a runtime error, as Color is not defined in js. The ts declaration just claims that there is some Color object in js, while in fact, without definition, there is none. Ti fix this we can add</p>
  
  <pre><code>var Color = {
     Red: 1,
     Green: 2,
     Blue: 3
  };
  </code></pre>
  
  <p>but now the enum implementation is not "ambient" in the sense that the typescript compiler does what a C++ compiler does, reducing the enum values at all occurencies to plain numbers. <strong>The current ambient declarations allow type checking but not such replacement.</strong></p>