title: How to call a method of a derived class in the constructor of this derived class
body: <p>I have a piece of code that used to work in TypeScript a few years ago, but now is begin compiled using Microsoft.TypeScript.MSBuild 4.5.3 (as part of a Microsoft.NET.Sdk.Web NET 5.0 project) and no longer works. Previously code must have been compiled using an older version of this compiler, but I can't pinpoint which version (it was a TypeScript project in Visual studio 2017 or older). Here is a stripped down version of my code:</p>
  <pre><code>class MyArray extends Array&lt;number&gt;{
      constructor(x: number)
      {
          super();
          this.foo(x);
      }
  
      foo(x: number) {
          // Do stuff with x
      }
  }
  </code></pre>
  <p>Creating a new instance of MyArray results in the exception: <strong>Uncaught TypeError: _this.foo is not a function</strong></p>
  <p>It appears to boil down to the constructor being compiled to:</p>
  <pre><code>var _this = _super.call(this) || this;
  _this.foo(x)
  </code></pre>
  <p>If I understand it correctly, <code>_this</code> is an instance of an <code>Array&lt;number&gt;</code> and knows nothing of my <code>foo</code> method.</p>
  <p>In the past the constructor would compile to:</p>
  <pre><code>_super.call(this);
  this.foo(x)
  </code></pre>
  <p>which would work.</p>
  <p>I desperately tried to find an answer to this problem on the internet, but had no luck. Adding to the confusion, intelisense and the compiler don't expect there to be a problem (probably because this code would work in a non-inherited class) and the debugger in the browser still firmly believes that <code>this</code> in my TypeScript constructor is an instance of <code>MyArray</code> rather than <code>Array&lt;number&gt;</code>.</p>
  <p><strong>Long story short, how can I call my <code>foo</code> method from the constructor of <code>MyArray</code> class?</strong></p>