title: exporting enum from typescript type definition file
body: <p>I'm writing the type definitions for a library I'm using. One function in the library identifies the mouse button clicked by an integer:</p>
  
  <pre class="lang-js prettyprint-override"><code> //index.d.ts
   export as namespace myLib;
   // activates the library listening for a specific mouse button
   function activate(button : number ) : void 
  </code></pre>
  
  <p>I introduced an enum to make this nicer:</p>
  
  <pre class="lang-js prettyprint-override"><code>//index.d.ts
  export as namespace myLib;
  export enum MouseButton {
      LEFT = 1,
      MIDDLE = 2,
      RIGHT = 4
  }
  
  export function activate(button : MouseButton ) : void;
  </code></pre>
  
  <p>Now, when I import this function and use it, everything compiles but I guess the enum is stripped and undefined when executed in the browser. The error message says <code>Cannot read property 'LEFT' of undefined</code>.</p>
  
  <p>Therefore I rearranged the files like so:</p>
  
  <pre class="lang-js prettyprint-override"><code>//MouseButton.ts
  export enum MouseButton {
      LEFT = 1,
      MIDDLE = 2,
      RIGHT = 4
  }
  
  //index.d.ts
  export as namespace myLib;
  import {MouseButton} from MouseButton;
  export {MouseButton} from MouseButton;
  export function activate(button : MouseButton ) : void;
  </code></pre>
  
  <p>Now I can <code>import {MouseButton} from "myLib/MouseButton"; import * as myLib from "myLib"</code>. But this requires two imports. Referencing <code>myLib.MouseButton</code> still compiles but doesn't run.</p>
  
  <p>Is there any way to import and reference the <code>MouseButton</code> enum via the <code>myLib</code> imported via the <code>import * as myLib</code> statement? I'm not only looking for an answer explaining how to do it but for one explaining why my solution doesn't work or why it isn't possible. Hints to resources explaining what's wrong are also appreciated</p>
  
  <p>PS: I also tried the syntax suggested here <a href="https://stackoverflow.com/questions/47701270/re-export-typescript-enum-from-namespace">re-export Typescript enum from namespace?</a> but that didn't work either.</p>
  
  <p>PPS: The module in question is a UMD module from the cornerstone project (<a href="https://github.com/cornerstonejs/cornerstone" rel="noreferrer">https://github.com/cornerstonejs/cornerstone</a>) used in an angular 6 project.</p>