title: Typescript - Returning a promise from a generic method
body: <p>I have an issue where I am trying to return a promise from one of my methods, however, it complains that the type 'is not assignable'. See example below:</p>
  
  <pre><code>interface Test {
      prop1: string
  }
  
  interface Interface {
      oneMethod&lt;T&gt;(): Promise&lt;T&gt;;
  }
  
  class implementation implements Interface {
      oneMethod&lt;Test&gt;(): Promise&lt;Test&gt; {
          return Promise.resolve({
              prop1: 'test'
          });
      }
  }
  </code></pre>
  
  <p>I get the error: </p>
  
  <pre><code>error TS2322: Type 'Promise&lt;{ prop1: string; }&gt;' is not assignable to type 'Promise&lt;Test&gt;'.
    Type '{ prop1: string; }' is not assignable to type 'Test'.
  </code></pre>
  
  <p>I have tried adding 'as Test' to the return object but that then returns the issue 'cannot be converted to Type Test'</p>
  
  <p>Annoyingly, this works fine:</p>
  
  <pre><code>class anotherImp {
  
      oneMethod(): Promise&lt;Test&gt; {
          return Promise.resolve({
              prop1: 'test'
          });
      }
  }
  </code></pre>
  
  <p>but this is not implementing my generic interface. If I remove the T from the oneMethod signature in the interface, then I get an error about the Promise not knowing T (Cannot find name 'T'). Removing from both gives me the error that Promise must implement a type (Generic type 'Promise' requires 1 type argument(s).)</p>
  
  <p>Any thoughts much appreciated.</p>
  
  <p>Thanks
  Iain</p>