title: How to pass a function as parameter to Promise in TypeScript?
body: <p>When trying to write a wrapper class for asynchronous DynamoDB calling, I failed with the attempt to wrap all the return statements with a function call as:</p>
  
  <pre><code>function composePromise(method: (params: any, callback: (err, res) =&gt; void) =&gt; void, params: any): Promise&lt;any&gt; {
      return new Promise&lt;any&gt;((resolve, reject) =&gt;
          method(params, (err, res) =&gt; {
              if (err) reject(err);
              else resolve(res);
          })
      );
  }
  
  create(params: any): Promise&lt;any&gt; {
      return composePromise(this._db.put, params);
  }
  </code></pre>
  
  <p>Which is strange, because after I move the promise in <code>create</code> without any change, it works.</p>
  
  <pre><code>create(params: any): Promise&lt;any&gt; {
      return new Promise&lt;any&gt;((resolve, reject) =&gt;
          this._db.put(params, (err, res) =&gt; {
              if (err) reject(err);
              else resolve(res);
          })
      );
  }
  </code></pre>
  
  <p>So I am guessing it might be some closure issue, but cannot figure out why. Could anyone please help me with that?</p>