title: How do you type a class decorator in typescript?
body: <p>What would be the correct way to write a class decorator which accepts only specific classes?</p>
  
  <p>I tried the following:</p>
  
  <pre><code>class Component {
    age: number;
  }
  
  function registerComponent(name: string) {
    return &lt;T extends Component&gt;(constructor: T): T =&gt; {
      return constructor as T;
    }
  }
  
  @registerComponent("demo")
  class C1 extends Component {
  
  }
  </code></pre>
  
  <p>Which results in:</p>
  
  <pre><code>Argument of type 'typeof C1' is not assignable to parameter of type 'Component'.
    Property 'age' is missing in type 'typeof C1'.
  </code></pre>
  
  <p><a href="http://www.typescriptlang.org/play/index.html#src=class%20Component%20%7B%0A%20%20age%3A%20number%3B%0A%7D%0A%20%20%20%20%0Afunction%20registerComponent(name%3A%20string)%20%7B%0A%20%20return%20%3CT%20extends%20Component%3E(constructor%3A%20T)%3A%20T%20%3D%3E%20%7B%0A%20%20%20%20return%20constructor%20as%20T%3B%0A%20%20%7D%0A%7D%0A%0A%40registerComponent(%22demo%22)%0Aclass%20C1%20extends%20Component%20%7B%0A%0A%7D%0A" rel="noreferrer">Try in TypeScript Repl</a></p>