title: Creating a map in typescript
body: <p>I create a map in typescript like this:</p>
  
  <pre><code>let typeMap = new Map();
  </code></pre>
  
  <p>And set a key: string value like this:</p>
  
  <pre><code>typeMap.set("key", "value");
  </code></pre>
  
  <p>I can successfully get value by doing this:</p>
  
  <pre><code>typeMap.get("key")
  </code></pre>
  
  <p>However, I want set multiple key value pairs to the map and setting each key value would be too much code. I tried doing this:</p>
  
  <pre><code>let typeMap = new Map&lt;string, string&gt;();
  typeMap = {
     "key1": "value1",
     "key2": "value2"
     //etc
  }
  </code></pre>
  
  <p>But I'm getting </p>
  
  <blockquote>
    <p>Object literal may only specify known properties and "key1" does not exist in type 'Map</p>
  </blockquote>
  
  <p>I also tried the following:</p>
  
  <pre><code>  type typeMap = {
      [key: string]: string
    }
    let typeMap = {
      "key1": "value1",
      "key2": "value2",
      "key3": "value3"
    }
  </code></pre>
  
  <p>If I try to get a static value like this:</p>
  
  <pre><code>typeMap["key1"]
  </code></pre>
  
  <p>It works. However, I have a variable that must be passed as key to get the value and when I try to do this:</p>
  
  <pre><code>typeMap[variable]
  </code></pre>
  
  <p>I'm getting:</p>
  
  <blockquote>
    <p>Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{ "key1": string; "key2": string; "key3": string; }'.</p>
    
    <p>No index signature with a parameter of type 'string' was found on type '{ "key1": string; "key2": string; "key3": string; }'</p>
  </blockquote>