title: Entity is not assignable to the same property in base type Service<Entity>: Generic default on another generic
body: <p>I'm trying to assign a generic type to another as default and return the assignee generic type in a function on an abstract class. I wanted it to be totally straightforward for the extended class for override it using the default value with no success.</p>
  
  <p>This is a part (reduced) of my abstract class:</p>
  
  <pre class="lang-js prettyprint-override"><code>export abstract class ServicioRest &lt;T&gt; {
  
      public listarPorId&lt;K = T&gt;(entidad?: T): Promise&lt;K&gt; {
          return new Promise&lt;K&gt;((resolve: Function, reject: (error: any) =&gt; void): void =&gt; {
              //some code
          });
      }
  
  }
  </code></pre>
  
  <p>And these are some ways I've tried to create my extended class. Just the last two (4 and 5) worked out:</p>
  
  <p><strong>1)</strong></p>
  
  <pre class="lang-js prettyprint-override"><code>class EntityService extends ServicioRest&lt;IEntity&gt; {
  
          public listarPorId(entidad?: IEntity): Promise&lt;IEntity&gt; {
              return super.listarPorId(entidad);
          }
  
      }
  </code></pre>
  
  <p><strong>2)</strong></p>
  
  <pre class="lang-js prettyprint-override"><code>class EntityService extends ServicioRest&lt;IEntity&gt; {
  
          public listarPorId&lt;IEntity&gt;(entidad?: IEntity): Promise&lt;IEntity&gt; {
              return super.listarPorId(entidad);
          }
  
      }
  </code></pre>
  
  <p><strong>3)</strong></p>
  
  <pre class="lang-js prettyprint-override"><code>class EntityService extends ServicioRest&lt;IEntity&gt; {
  
          public listarPorId(entidad?: IEntity) {
              return super.listarPorId(entidad);
          }
  
      }
  </code></pre>
  
  <p><strong>4)</strong></p>
  
  <pre class="lang-js prettyprint-override"><code>class EntityService extends ServicioRest&lt;IEntity&gt; {
  
          public listarPorId&lt;K=IEntity&gt;(entidad?: IEntity): Promise&lt;K&gt; {
              return super.listarPorId(entidad);
          }
  
      }
  </code></pre>
  
  <p><strong>5)</strong></p>
  
  <pre class="lang-js prettyprint-override"><code>class EntityService extends ServicioRest&lt;IEntity&gt; {
  
          public listarPorId&lt;K&gt;(entidad?: IEntity): Promise&lt;K&gt; {
              return super.listarPorId(entidad);
          }
  
      }
  </code></pre>
  
  <p>The ones that don't work make the compiler alert on this error:</p>
  
  <p><strong>ERROR in src/app/modules/rest/models/servicio-rest.spec.ts(31,16): error TS2416: Property 'listarPorId' in type 'EntityService' is not assignable to the same property in base type 'ServicioRest'.
    Type '(entidad?: IEntity...' is not assignable to type <code>'&lt;K = IEntity&gt;</code>(entidad: IEntity...'.
      Type 'Promise<code>&lt;IEntity&gt;</code>' is not assignable to type 'Promise<code>&lt;K&gt;</code>'.
        Type 'IEntity' is not assignable to type 'K'.</strong></p>
  
  <p>Although the last two work out, I don't like them because I can't restrict <strong>K</strong> to be IEntity. Is there any way to achive that restriction?</p>