title: Using "this" parameter in Typescript static methods doesn't narrow the type to the current class?
body: <p>This is best explained using an example. I need to reference the current class in a static method, this works as expected:</p>
  <pre><code>class Cls {
    static fn&lt;T extends typeof Cls&gt;(
      this: T,
      arg: T extends typeof Cls ? true : false,
    ) {}
  }
  
  Cls.fn(true);
  Cls.fn(false); // Argument of type 'false' is not assignable to parameter of type 'true'.
  </code></pre>
  <p>However, when calling <code>Cls.fn</code> from another static method, it doesn't work:</p>
  <pre><code>class Cls {
    static fn1&lt;T extends typeof Cls&gt;(
      this: T,
      arg: T extends typeof Cls ? true : false,
    ) {}
  
    static fn2&lt;T extends typeof Cls&gt;(this: T) {
      this.fn1(true); // Argument of type 'true' is not assignable to parameter of type 'T extends typeof Cls ? true : false'.
    }
  }
  </code></pre>
  <p><a href="https://www.typescriptlang.org/play?#code/MYGwhgzhAEDCIwN4FgBQ1oQC5iwS2GgDMA7AHgBVoBTADy2pIBMYsBPAB2oHsi4EAfAAo0GDFgAWeCAC5oFADSixYAE4BzOVToNmrTjz7wYAfmhZVAV2rQ5RMAmpL00AJTREAXzTLsuAsQkAEyUNPSMLOYGvPwQwpLSWu4oLuJSEAB0pEIW1q4A3MreqMVAA" rel="nofollow noreferrer">TS Playground</a></p>
  <p>Interestingly, it works if I remove <code>fn2</code>'s generic or do <code>this.fn1&lt;typeof Cls&gt;(true)</code>. This means the error is related to the type of <code>this</code>. I think it has to do with <code>this</code> referring to any subclass of <code>Cls</code> as opposed to exactly <code>Cls</code>. However, even if <code>this</code> is a subclass of <code>Cls</code>, <code>T extends typeof Cls</code> would still be true.</p>
  <p>Is this a bug where Typescript uses the wrong value for <code>this</code>? If it's not a bug, how can I fix it?</p>
  <p>In my actual code, I need to reference the current class because the method accepts different arguments depending on the subclass.</p>
  <p><strong>Edit:</strong> <a href="https://www.typescriptlang.org/play?#code/FAYwNghgzlAEBC0CmsDexaygFwtgliLAGYB2APACqxIAe2SpAJnNgJ4AOSA9sQsgD4AFBkyxsAC3xQAXLEoAaUZggAnAOZzqdBs1acefAMoBXAEawA-LADkUczdhybZ5DaWYAlGgC%20wP6CQMLCmFjqMLPxQKOiY0qGwALziqiZIANzAojh4hCSkAExC3rFiktIAdGRCLm6emWLiUlBVpDX2Zjb1ogGYOQREZADMVDT0EfpcvCHmwuWy8iXKTZXVtdFdDWXNre0O9bAA9IfyzbBg%20KQo0qQ22LAA7tyqANaX6rDQY1wgDEwVPX8WUQ0V26yQm2AIKQYI6kNCsP2mQRa1cG26QA" rel="nofollow noreferrer">here's a more realistic example using subclasses</a></p>