title: Method chaining with async in Typescript (just found out a solution)
body: <p>I am writing a module aims at preparing a query before calling it to database. The code in vanilla javascript worked pretty well, but when I tried to write it in Typescript, I got the error: <code>Type of 'await' operand must either be a valid promise or must not contain a callable 'then' member</code></p>
  <p>My code in Javascript:</p>
  <pre><code>class QueryBuilder {
    constructor(query) {
      this.query = query;
    }
  
    sort(keyOrList, direction) {
      this.query = this.query.sort(keyOrList);
      return this;
    }
  
    skip(value) {
      this.query = this.query.skip(value);
      return this;
    }
  
    limit(value) {
      this.query = this.query.limit(value);
      return this;
    }
  
    then(cb) {
      cb(this.query.toArray());
    }
  }
  </code></pre>
  <p>Code in Typescript:</p>
  <pre><code>class QueryBuilder {
    public query: Cursor;
    constructor(query: Cursor) {
      this.query = query;
    }
  
    public sort(keyOrList: string | object[] | object, direction: any) {
      this.query = this.query.sort(keyOrList);
      return this;
    }
  
    public skip(value: number) {
      this.query = this.query.skip(value);
      return this;
    }
  
    public limit(value: number) {
      this.query = this.query.limit(value);
      return this;
    }
  
    public then(cb: Function) {
      cb(this.query.toArray());
    }
  }
  </code></pre>
  <p>How I called these methods:</p>
  <pre><code>const query = await new QueryBuilder(Model.find())
      .limit(5)
      .skip(5)
  </code></pre>
  <p>Hope someone can help me with this. Thanks in advance.</p>
  <p>*Updated:
  I extended QueryBuilder class from the buitin Promise, then overrided <code>then</code> method by <code>QueryBuilder.prototype.then</code>.The code is now executable but I didn't truly understand the <code>super(executor)</code> in the constructor. It's required an <code>executor(resolve: (value?: T | PromiseLike&lt;T&gt; | undefined) =&gt; void, reject: (reason?: any) =&gt; void): void</code> so I just simply created a dumb executor. How does it affect to the code?</p>
  <pre><code>class QueryBuilder&lt;T&gt; extends Promise&lt;T&gt; {
    public query: Cursor;
    constructor(query: Cursor) {
      super((resolve: any, reject: any) =&gt; {
        resolve(&quot;ok&quot;);
      });
      this.query = query;
    }
  
    public sort(keyOrList: string | object[] | object, direction?: any) {
      this.query = this.query.sort(keyOrList);
      return this;
    }
  
    public skip(value: number) {
      this.query = this.query.skip(value);
      return this;
    }
  
    public limit(value: number) {
      this.query = this.query.limit(value);
      return this;
    }
  }
  
  QueryBuilder.prototype.then = function (resolve: any, reject: any) {
    return resolve(this.query.toArray());
  };
  </code></pre>