title: Object with generic keys in typescript
body: <p>I'd like to create a common function which will take an object, then do some transformations and return new object with same keys and different values. I'm trying to make it "strongly-typed", so everyone who uses it will have benefits of TS and non-existing keys should throw an error.</p>
  
  <p>What I have for now:</p>
  
  <pre><code>const hash = {
    "first": 1,
    "second": 2,
    "third": 3,
  }
  
  type Mapper&lt;T&gt; = {
    [key in keyof T]: number
  }
  
  type Result&lt;T&gt;= {
    [key in keyof T]: () =&gt; number
  }
  
  const transform = &lt;T&gt;(mapper: Mapper&lt;T&gt;) =&gt; {
    const result = {} as Result&lt;T&gt;
  
    (Object.keys(mapper) as (keyof T)[]).map(key =&gt; {
      result[key] = () =&gt; mapper[key]
    })
  
    return result
  }
  
  type Hash = typeof hash
  
  const a = transform&lt;Hash&gt;(hash)
  
  a.first()
  // a.fifth() OK error
  </code></pre>
  
  <p>It works well, but I'm looking for solutions to solve this:</p>
  
  <ol>
  <li><p>Remove type assertion <code>const result = {} as Result&lt;T&gt;</code></p></li>
  <li><p>Remove type assertion <code>(Object.keys(mapper) as (keyof T)[])</code> (or use <code>Object.entries</code>, but seems it also requires type assertion in this case)</p></li>
  </ol>
  
  <p>Could I implement the same, but in more "clean" way in Typescript?</p>