title: How to use Typescript generics recursively?
body: <p>I am having an issue using recursive generics.</p>
  
  <p>I created an interface using generics. The idea is a branch can have many child branches which are also generics. This is my code ( I cut it down for posting)</p>
  
  <pre><code>import Contact from 'Business/Models/Contact';
  import Office from 'Business/Models/Office';
  
  export interface BranchInterface&lt;T&gt; {
      children: Array&lt;BranchInterface&lt;T&gt;&gt;;
      record: T;
  }
  
  export class Branch&lt;T&gt; implements BranchInterface&lt;T&gt; {
  
      public children: Array&lt;BranchInterface&lt;T&gt;&gt; = [];
  
      constructor(public record: T) {}
  }
  
  
  const newOffice = new Office();
  
  const rootBranch = new Branch&lt;Office&gt;(newOffice);
  
  rootBranch.children = Array&lt;Branch&lt;Contact&gt;&gt;(); &lt;&lt; is the issue
  </code></pre>
  
  <p>The issue is that when I construct an <code>Office</code> branch, the children array is being constructed as <code>Office</code> type. </p>
  
  <p>This means when I try to assign an array of <code>Contact</code> branches as the children of the <code>Office</code> branch typescript throws the following error;</p>
  
  <p><code>Type 'Branch&lt;Contact&gt;[]' is not assignable to type 'Branch&lt;Office&gt;[]'...</code></p>
  
  <p>The reason for doing this is because the type of branches are unknown and I don't really want to use <code>any</code> either if I can avoid it.</p>
  
  <p>So, How would I resolve this?</p>