title: Using an enum as a dictionary key
body: <p>I'm trying to create a guaranteed lookup for a given enum. As in, there should be exactly one value in the lookup for every key of the enum. I want to guarantee this through the type system so that I won't forget to update the lookup if the enum expands. I tried this:</p>
  
  <pre><code>type EnumDictionary&lt;T, U&gt; = {
      [K in keyof T]: U;
  };
  
  enum Direction {
      Up,
      Down,
  }
  
  const lookup: EnumDictionary&lt;Direction, number&gt; = {
      [Direction.Up]: 1,
      [Direction.Down]: -1,
  };
  </code></pre>
  
  <p>But I'm getting this weird error:</p>
  
  <blockquote>
    <p>Type '{ [Direction.Up]: number; [Direction.Down]: number; }' is not assignable to type 'Direction'.</p>
  </blockquote>
  
  <p>Which seems weird to me because it's saying that the type of <code>lookup</code> should be <code>Direction</code> instead of <code>EnumDictionary&lt;Direction, number&gt;</code>. I can confirm this by changing the <code>lookup</code> declaration to:</p>
  
  <pre><code>const lookup: EnumDictionary&lt;Direction, number&gt; = Direction.Up;
  </code></pre>
  
  <p>and there are no errors.</p>
  
  <p>How can I create a lookup type for an enum that guarantees every value of the enum will lead to another value of a different type?</p>
  
  <p>TypeScript version: 3.2.1</p>