title: Typescript mixin constrained to typeof class
body: <p>I was following this example from the <a href="https://www.typescriptlang.org/docs/handbook/mixins.html" rel="nofollow noreferrer">Typescript documentation</a>:</p>
  <pre><code>class Sprite {
    name = &quot;&quot;;
    x = 0;
    y = 0;
  
    constructor(name: string) {
      this.name = name;
    }
  }
  
  type GConstructor&lt;T = {}&gt; = new (...args: any[]) =&gt; T;
  
  type Spritable = GConstructor&lt;typeof Sprite&gt;;
  </code></pre>
  <p>Next, implemented a function that generates a class extending this type like this:</p>
  <pre><code>function Example&lt;TBase extends Spritable&gt;(Base: TBase) {
    return class Example extends Base {
      hello() {
        console.log(&quot;hello&quot;);
      }
    };
  }
  </code></pre>
  <p>I assumed that I would then utilise this Mixin like this:</p>
  <pre><code>const x = Example(Sprite);
  </code></pre>
  <p>However, this throws the error</p>
  <pre><code>Argument of type 'typeof Sprite' is not assignable to parameter of type 'Spritable'.
  </code></pre>
  <p>If I modify the param passed into the generic constructor to be <code>type Spritable = GConstructor&lt;Sprite&gt;;</code>, the above code works.</p>
  <p>However, in the typescript docs it's implemented using <code>typeof</code> which throws me an error. What am I doing wrong here?</p>