title: Generic factory based on interface TypeScript
body: <p>I want to implement generic method which will return concrete type based on provided interface. Is this even possible in TypeScript?</p>
  
  <p>Here is my pseudo example:</p>
  
  <pre><code>interface IDog {
    canRun: boolean;
  }
  
  interface IBird {
    canFly: boolean;
  }
  
  class Dog implements IDog {
    canRun: boolean;
  }
  
  class Bird implements IBird {
    canFly: boolean;
  }
  
  function createInstance&lt;T&gt;(): T {
    const key =  typeof T;
  
    switch (key) {
      case IBird:
        return new Bird();
       return 
        case IDog:
        return new Dog();
      default:
        break;
    }
  }
  
  // concrete is Dog
  const concrete = createInstance&lt;IDog&gt;();
  </code></pre>
  
  <p><code>createInstance()</code> method is a raw example of what I am trying to achieve, it will not compile!</p>
  
  <p>I would like to provide interface type to <code>createInstance()</code> method and implement some logic which will create concrete type for provided interface.</p>
  
  <p>Is it possible in TypeScript?</p>