title: Undefined TypeScript enum at compile time
body: <p>I have an enum defined in <code>types.ts</code>:</p>
  
  <pre class="lang-js prettyprint-override"><code>export enum Handedness {
    Left,
    Right,
    Both,
  }
  
  export type State = {
    count: number
    handedness: Handedness
  }
  </code></pre>
  
  <p>and I have an object being initialized in <code>state.ts</code>:</p>
  
  <pre class="lang-js prettyprint-override"><code>import { State, Handedness } from './types'
  
  export const initial: State = {
    count: 0,
    handedness: Handedness.Both
  }
  </code></pre>
  
  <p>When I run tests (via <code>jest</code>) for this project, <code>state.ts</code> generates an error <code>TypeError: Cannot read property 'Both' of undefined</code>, telling me that <code>Handedness</code> isn't defined at the time it's referenced. But I'm exporting it from its module and importing it before I use it... so it should be defined.</p>
  
  <p>I've found other similar questions asking about undefined enums, but they seem to all be asking about runtime. This is a compile time problem as far as I can tell.</p>
  
  <p>I don't see what I would be doing wrong here. I import other types in other places without issue. But this enum simply doesn't want to work. What is going on here and how can I work around it?</p>