title: How to strictly type an identity function as a specific transform?
body: <p>How do I define a function type <code>transform&lt;I, O&gt;</code> that takes input of type I and return output of type O, and then define an <code>identity</code> function as a specific implementation of a <code>transform</code>? </p>
  
  <p>For example</p>
  
  <pre><code>type transform&lt;I, O&gt; = (input: I) =&gt; O;
  
  const identity = // ...
  </code></pre>
  
  <p>Such that I can define a function</p>
  
  <pre><code>const mapToObject = &lt;K, V, O&gt;(
    map: Map&lt;K, V&gt;, 
    transformValue: transform&lt;V, O&gt; = identity
  ) =&gt; Array.from(map.entries()).reduce((obj, [key, val]) =&gt; {
    obj[key] = transformValue(value);
    return obj;
  }, {});
  </code></pre>
  
  <p>The <code>mapToObject</code> function should take a <code>Map</code> and <code>transformValue</code> function and convert the map to a simple JS object, applying <code>transformValue</code> to each value in the map. <code>transformValue</code> should default to the <code>identity</code> function <code>v =&gt; v</code>. </p>
  
  <p>The identity function mapping <code>any</code> to <code>any</code> works, though I am interested in a strictly typed solution. </p>