title: Type error when a generic extends a class
body: <p>This TypeScript code:</p>
  
  <pre><code>class Foo {}
  
  function bar&lt;T extends Foo&gt;(): void {
    let value: T = new Foo();
  }
  </code></pre>
  
  <p>Gives this error:</p>
  
  <pre><code>foo.ts(4,7): error TS2322: Type 'Foo' is not assignable to type 'T'.
  </code></pre>
  
  <p>This seems wrong to me: <code>T</code> extends from <code>Foo</code>, so <code>Foo</code> should be compatible with <code>T</code></p>
  
  <p>Why does this error happen?</p>
  
  <p>As proof that using <code>T extends Foo</code> does work correctly in <em>some</em> situations, here is another example which does not give a type error:</p>
  
  <pre><code>class Foo {
    protected _foo: number;
  
    getFoo(): number {
      return this._foo;
    }
  }
  
  class Bar extends Foo {
    protected _bar: number;
  }
  
  function bar&lt;T extends Foo&gt;(a: T) {
    return a.getFoo();
  }
  
  bar(new Foo());
  bar(new Bar());
  </code></pre>
  
  <p>Note that the <code>bar</code> function cannot access any properties on <code>Bar</code>, it can only access properties on <code>Foo</code>, which is exactly what I expect.</p>
  
  <p>Also note that we are able to assign a value of type <code>Foo</code> to type <code>T</code>, but only by passing in a <code>Foo</code> as an argument, not by using <code>let a: T = new Foo()</code></p>
  
  <hr>
  
  <p>The above code is a very small reduced test case of my much larger application. I am trying to do this:</p>
  
  <pre><code>class Foo {
      // Various properties and methods
      protected _foo: number;
  }
  
  
  class Bar extends Foo {
      // Various properties and methods
      protected _bar: number;
  }
  
  
  class Qux&lt;T extends Foo&gt; {
      // Various properties and methods which work on Array&lt;T&gt;
      protected _list: Array&lt;T&gt;;
  
      get list(): Array&lt;T&gt; {
          // Do initialization / caching / etc.
          return this._list;
      }
  }
  
  
  class Corge&lt;T extends Bar&gt; extends Qux&lt;T&gt; {
      constructor() {
          super();
          this._list = [new Bar()];
          let value: Array&lt;Bar&gt; = this.list;
      }
  }
  </code></pre>
  
  <p>This allows me to put generic methods into <code>Qux</code> which work on <code>Array&lt;Foo&gt;</code>, and those methods will also work for <code>Corge</code>, even though <code>Corge</code> uses <code>Array&lt;Bar&gt;</code></p>
  
  <p>But this doesn't work, because of the type error.</p>