title: Replace Generic Interface Type Parameter
body: <p>I am attempting to create a generic function interface for functor map, that respects the interface provided. In the code shown below, I would like the value of <code>mb</code> to be of type <code>Maybe&lt;number&gt;</code>, as opposed to the actual type <code>Functor&lt;number&gt;</code>.</p>
  
  <p>I do realize that one possible solution is to add an overload to the interface <code>FMap</code>. The reason I am not happy with this solution is that I would like this code to reside in a package, allowing users to create implementations for <code>Functor</code>, and have the behavior I described above when using the function <code>map</code>.</p>
  
  <pre class="lang-js prettyprint-override"><code>interface Functor&lt;A&gt; {
    map&lt;B&gt;(fn: (a: A) =&gt; B): Functor&lt;B&gt;;
  }
  
  interface FMap {
    &lt;A, B&gt;(fn: (a: A) =&gt; B, Fa: Functor&lt;A&gt;): Functor&lt;B&gt;;
  }
  
  const map: FMap = (fn, Fa) =&gt; (
    Fa.map(fn)
  );
  
  class Maybe&lt;A&gt; implements Functor&lt;A&gt; {
    constructor(private readonly a: A) {}
    map&lt;B&gt;(fn: (a: A) =&gt; B): Maybe&lt;B&gt; {
      return new Maybe&lt;B&gt;(fn(this.a));
    }
  }
  
  
  const sqr = (x: number) =&gt; x*x;
  const ma = new Maybe(5);
  const mb = map(sqr, ma);
  </code></pre>
  
  <p>I would like some means of expressing the following semantics:</p>
  
  <pre class="lang-js prettyprint-override"><code>// Theoretical Code
  
  interface PretendFMap {
    &lt;A, B, FA extends Functor&lt;A&gt;&gt;(fn: (a: A) =&gt; B, Fa: FA): FA extends (infer F)&lt;A&gt; ? F&lt;B&gt; : never;
  }
  </code></pre>
  
  <p>This however does not function, as a generic interface, without a type parameter is not a valid TypeScript type, i.e. an interface such as <code>Functor</code> requires a type parameter to be considered a type, <code>Functor</code> itself is not a valid type.</p>
  
  <p>If there are currently no means of expressing these semantics, any suggestions regarding a solution that requires as little code as possible on the side of the user would be greatly appreciated.</p>
  
  <p>Thank you in advance for your time and consideration.</p>