title: How to extend a typescript class with a get property?
body: <p>I get an instance of an object with say type <code>A</code>. How do I extend this with a getter function in Typescript? Adding a function I do</p>
  
  <pre><code>A.prototype.testFunction = function () {
    if(this.something) {
      return this.something;
    }
   return null;
  }
  </code></pre>
  
  <p>I extend the type in an <code>index.d.ts</code> file such as:</p>
  
  <pre><code>interface A {
      testFunction (): SomeType|null;
  }
  </code></pre>
  
  <p>But how am I supposed to add it if I want to to appear as a getter function, and not just as a function?</p>
  
  <p>I tried looking at <code>Object.defineProperty()</code> but Typescript itself doesn't seem to be too happy working with that one, referring to the wrong instance of <code>this</code> in the following code:</p>
  
  <pre><code>Object.defineProperty(A.prototype, "testGet", {
      get: function () {
          if(this.something) { // &lt;== this appears to not refer to type A
            return this.something;
          }
          return null;
      },
      enumerable: false,
      configurable: true
  }); 
  </code></pre>