title: Typescript: subclass/extend of Promise: does not refer to a Promise-compatible constructor value
body: <p>I'm trying to cancel my <code>async</code> method call in Typescript.</p>
  
  <p>To do this, I have created a new Promise type, which inherits from <code>Promise</code>:</p>
  
  <pre class="lang-js prettyprint-override"><code>class CancelablePromise&lt;T&gt; extends Promise&lt;T&gt;{
  
      private cancelMethod: () =&gt; void;
      constructor(executor: (resolve: (value?: T | PromiseLike&lt;T&gt;) =&gt; void, reject: (reason?: any) =&gt; void) =&gt; void, cancelMethod: () =&gt; void) {
          super(executor);
          this.cancelMethod = cancelMethod;
      }
  
      //cancel the operation
      public cancel() {
          if (this.cancelMethod) {
              this.cancelMethod();
          }
      }
  }
  </code></pre>
  
  <p>But when I'm trying to use it:</p>
  
  <pre class="lang-js prettyprint-override"><code>async postFileAjax&lt;T&gt;(file: File): CancelablePromise&lt;T&gt; { ... }
  </code></pre>
  
  <p>I get the error:</p>
  
  <blockquote>
    <p>Error     Build:Type 'typeof CancelablePromise' is not a valid async function return type in ES5/ES3 because it does not refer to a Promise-compatible constructor value.</p>
  </blockquote>
  
  <p>If I using the type declaration and return the <code>CancelablePromise</code>, like this then it compiles:</p>
  
  <pre class="lang-js prettyprint-override"><code>async postFileAjax&lt;T&gt;(file: File): Promise&lt;T&gt;  { 
       ...
       return CancelablePromise(...);
  }
  </code></pre>
  
  <p>What am I doing wrong? I see that in ES6 you could subclass the <code>Promise</code> (see <a href="https://stackoverflow.com/a/29351519/201303">stackoverflow question</a>), so I would expect it also in TypeScript.</p>
  
  <p>Using Typescript 2.1 and targeting es5</p>