title: TypeScript "extends" generic constraint
body: <p>I am using the <code>extends</code> constraint in TypeScript, like so:</p>
  
  <pre><code>class Animal {}
  class Lion extends Animal {}
  class Bear extends Animal {}
  
  class ZooKeeper&lt;T extends Animal&gt; {
      constructor(p: T = new Animal()) {
  
      }
  }
  
  new ZooKeeper(new Animal());
  </code></pre>
  
  <p>But <code>p: T = new Animal()</code> contains an error:</p>
  
  <blockquote>
    <p>Type 'Animal' is not assignable to type 'T'.</p>
    
    <p>constructor Animal(): Animal</p>
  </blockquote>
  
  <p><strong>Why</strong>, and what do I do, in order that I can use <code>Animal</code>, in place of <code>Animal</code> subtypes?</p>
  
  <p><a href="https://www.typescriptlang.org/play/index.html#src=class%20Animal%20%7B%7D%0D%0Aclass%20Lion%20extends%20Animal%20%7B%7D%0D%0Aclass%20Bear%20extends%20Animal%20%7B%20%7D%0D%0A%0D%0Aclass%20ZooKeeper%3CT%20extends%20Animal%3E%20%7B%0D%0A%20%20%20%20constructor(p%3A%20T%20%3D%20new%20Animal())%20%7B%0D%0A%0D%0A%20%20%20%20%7D%0D%0A%7D%0D%0A%0D%0Anew%20ZooKeeper(new%20Animal())%3B" rel="nofollow noreferrer">Source</a></p>