title: Typescript generics with factory function
body: <p>I have a class that I want to extend with a factory class that will return the correct class based on the input. </p>
  
  <pre><code>class Base&lt;S&gt; {
    prop: S;
    base() { }
  }
  
  class A&lt;S&gt; extends Base&lt;S&gt; {
    a() { }
  }
  
  class B&lt;S&gt; extends Base&lt;S&gt; {
    b() { }
  }
  
  
  interface TypeA {
    propA: any;
  }
  
  interface TypeB {}
  
  function isTypeA(params: TypeA | TypeB): params is TypeA {
    return (params as TypeA).propA !== undefined;
  }
  
  function factory(params: TypeA): typeof A;
  function factory(params: TypeB): typeof B;
  function factory(params: TypeA | TypeB): typeof A | typeof B {
    if (isTypeA(params)) {
      return A;
    } else {
      return B;
    }
  }
  
  const param: TypeA = { propA: {} };
  const param2: TypeB = {};
  
  class Test extends factory(param) { }
  </code></pre>
  
  <p>In addition to that, I need to pass a generics all the way up. How can I pass the generic from the factory function to the <code>Base</code> class?</p>