title: Typescript: define function, which transforms an object, keeping keys
body: <p>I need to define a function, which accepts an object of this type:</p>
  
  <pre><code>interface Source&lt;A&gt; {
      [index: string]: A
  }
  </code></pre>
  
  <p>and transforms that object, <strong>keeping the keys</strong>, but replaces a values:</p>
  
  <pre><code>interface Target&lt;B&gt; {
      [index: string]: B
  }
  </code></pre>
  
  <p>and I also want to keep typechecking for that case. This is example:</p>
  
  <pre><code>function transform(source) {
      var result = {}
      Object.keys(source).forEach((key) =&gt; {
          result[key] = source[key] + "prefix"
      })
  }
  
  var target = transform({
      "key1": 1,
      "key2": 2,
  })
  
  // now target has a {"key1": "1prefix", "key2": "2prefix"}
  
  var three = target.key3 // I want to get type error here on compile-time
  </code></pre>