title: Create instance of generic type in TypeScript
body: <p>I'm trying to instantiate an abstract class, searching around suggests this isn't possible without a bunch of odd hoops but I can't find a way to make it work for my situation</p>
  <p>What I'm trying to do is create a generic abstract factory that has a non-abstract function which generates a new instance of the generic type</p>
  <pre><code>abstract class GenericItemFactory&lt;T&gt; {
    create(attribute: any): T {
        return new T(attribute);
    }
  }
  </code></pre>
  <p>This seems impossible in TypeScript from my searching, please correct me if I'm wrong</p>
  <p>Since this isn't possible, and since I have 6 (and growing) instances of the GenericItemFactory, I end up needing to write exactly identical functions for <code>create</code>. Writing the exact same code 6 times screams at me the need for abstraction but I can't figure out how to do it.</p>
  <p>I saw a few tricks of passing in the type and being able to create a generic instance but couldn't figure out how to adapt to my use</p>
  <p>These as a suite of Factors that expose a <code>create</code> method, and are exported in an object like</p>
  <pre><code>class ItemA extends Item {
    attribute: any;
  }
  
  class ItemAFactory extends GenericItemFactory {
    create(attribute: any): ItemA {
        return new ItemA(attribute);
    }
  }
  </code></pre>
  <p>... repeated for each Item Type! and then exported as</p>
  <pre><code>const items: { [itemKey: string]: GenericItemFactory } = {
    itemA: new ItemAFactory(),
    itemB: new ItemBFactory(),
    itemC: new ItemCFactory(),
    ...
  }
  </code></pre>
  <p>How can I instantiate that generic type like I'm trying, or otherwise restructure my factor to be able to accomplish? Thanks!</p>