title: How do I extend a host object (e.g. Error) in TypeScript
body: <p>I would like to extend the host object <code>Error</code> to a custom <code>UploadError</code> class. The following example fails when I compile:</p>
  
  <pre><code>class UploadError extends Error {
      constructor(message: string, private code: number) {
          super(message);
      }
  
      getCode(): number {
          return this.code;
      }
  }
  </code></pre>
  
  <p>When I run the TypeScript compiler <code>tsc</code> I get the following error:</p>
  
  <pre><code>UploadError.ts(1,0): A export class may only extend other classes, Error is an interface.
  </code></pre>
  
  <p>It seems <code>Error</code> is defined as an interface. If anyone knows what the name of the implementation is it would make me very happy :-)</p>
  
  <h1>Update: I want to use Typescripts inheritance not prototypical inheritance like I currently employ to hack around this:</h1>
  
  <pre><code>function UploadError (message: string, code: number) {
      this.message = message;
      this.code = code;
  }
  
  UploadError.prototype = new Error();
  
  UploadError.prototype.constructor = UploadError;
  
  UploadError.prototype.getCode = (): number =&gt; {
      return this.code;
  }
  </code></pre>