title: Typescript create map object with nested property
body: <p>It seemed very easy but I really cannot make it work. I'm trying to map my object into another object with only nested property. Example:</p>
  
  <pre><code> const child1: Child&lt;string&gt; = { nested: "one" };
      const child2: Child&lt;number&gt; = { nested: 2 };
  
      type Child&lt;T&gt; = { nested: T };
      const abc = {
        child1,
        child2
  }
  
  const nestedOnly = {
    child1: abc.child1.nested,
    child2: abc.child2.nested
  }
  </code></pre>
  
  <p>How can I get write a generic function that will take any object as a parameter and return object wit nested properties only without losing particular types? It would work in similar way to Array.map. I tried this:</p>
  
  <pre><code>function get&lt;T&gt;(ac: T){
    return Object
      .keys(ac)
      .reduce((result, currentKey) =&gt; {
        result[currentKey] = ac[currentKey].nested
        return result;
      }, {});
  }
  </code></pre>
  
  <p>But it loses typings. I also tried to create mapped type in typescript and cast it inside this function but I couldn't work out how this type should look like.</p>
  
  <p>This is a type I came up with:</p>
  
  <pre><code>type NestedType&lt;T extends typeof abc&gt; = {[P in keyof T]: T[P]['nested']}
  </code></pre>
  
  <p>It seems to work fine however I need to get rid of typeof abc here because it has to be generic function. Is there a way to say T[P] has to have 'nested' property in this type ?</p>