title: TypeScript: Equivalent of C#'s Generic Type Constraint for extending class?
body: <p>I am attempting to write a protected abstract class which can take the subclass type as a type argument in the superclass constructor's method signature.</p>
  
  <p>What I am looking for is similar to C#'s Generic Type Constraint (<code>where</code> keyword) so that I can use a child type in a parameter list.</p>
  
  <pre><code>//                    where T : &lt;base class name&gt;
  BaseAuthController&lt;T&gt; where T : BaseAuthController
  </code></pre>
  
  <p><strong>Current superclass</strong></p>
  
  <pre><code>export abstract class BaseAuthController {
      protected constructor(
          protected dialogRef:
              //This class shouldn't know about child classes
              MatDialogRef&lt;Child1DialogComponent&gt; |
              MatDialogRef&lt;Child2DialogComponent&gt; |
              MatDialogRef&lt;Child3DialogComponent&gt;
      ) {
  
      }
  }
  </code></pre>
  
  <p><strong>Current subclass</strong></p>
  
  <pre><code>export class Child1DialogComponent extends BaseAuthController {
      constructor(dialogRef: MatDialogRef&lt;Child1DialogComponent&gt;) {
          super(dialogRef);
      }
  }
  </code></pre>
  
  <p><strong>Ideal superclass</strong></p>
  
  <pre><code>export abstract class BaseAuthController&lt;T&gt; {
      protected constructor(protected dialogRef: MatDialogRef&lt;T&gt;) {
  
      }
  }
  </code></pre>
  
  <p>References</p>
  
  <ul>
  <li><a href="https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/generics/constraints-on-type-parameters" rel="nofollow noreferrer">C# Generic Type Constraint Reference</a></li>
  <li><a href="https://www.typescriptlang.org/docs/handbook/generics.html" rel="nofollow noreferrer">TypeScript Generics Reference</a></li>
  <li><a href="https://stackoverflow.com/q/45493893/2831961">Possibly related SO Post</a></li>
  </ul>