title: Map set different types of value depending on key type in Typescript
body: <p>I want to use Map to implement a Trie, so I created a TrieNodeMap type. The TrieNodeMap has two types of keys: a single letter OR a '$' which means the end of a word.
  Key with a letter maps inner TrieNodeMap and '$' maps word's info object.</p>
  <p>This is what I wrote:</p>
  <pre><code>type Char = 'a' | 'b' | 'c' | 'd' // just name a few chars;
  type TrieNodeMap = Map&lt;Char, TrieNodeMap&gt; | Map&lt;'$', object&gt;;
  </code></pre>
  <p>However, when I try to use it, the editor shows an error around <code>'a' as Char</code>: &quot;TS2345: Argument of type 'string' is not assignable to parameter of type 'never'.&quot;</p>
  <pre><code>let node: TrieNodeMap = new Map();
  node.set('a' as Char, new Map());
  </code></pre>
  <p>Have I done something wrong, why it seems that the key of TrieNodeMap is a never type?</p>