title: How to use ImmutableJS Map with TypeScript
body: <p>I have a tree structure that looks something like this:</p>
  
  <pre><code>interface TreeData {
    id : number;
    text : string;
    children : TreeData[];
  }
  </code></pre>
  
  <p>I want to wrap this up into an Immutable Map but since I'm using TypeScript, I would like some type safety around using get and set.  I found 2 articles online for suggestions on how one might be able to do this, see:</p>
  
  <p><a href="https://github.com/facebook/immutable-js/issues/683" rel="nofollow noreferrer">https://github.com/facebook/immutable-js/issues/683</a>
  <a href="https://blog.mayflower.de/6630-typescript-redux-immutablejs.html" rel="nofollow noreferrer">https://blog.mayflower.de/6630-typescript-redux-immutablejs.html</a></p>
  
  <p>However my problem is that my TreeData contains a list of TreeData children.  If I define my ImmutableMap this way:</p>
  
  <pre><code>export interface ImmutableMap&lt;T, K, V&gt; extends Map&lt;K, V&gt; {
    get&lt;I extends keyof T&gt;( key : I &amp; K ) : T[I] &amp; V;
    set&lt;S extends keyof T&gt;( key : S &amp; K, value : T[S] &amp; V ) : Map&lt;K, V&gt;;
  }
  </code></pre>
  
  <p>Then when I try to define the following, I get a typescript error message:</p>
  
  <pre><code>type ImmutableTreeData = ImmutableMap&lt;TreeData, string, string | List&lt;ImmutableTreeData&gt;&gt;;
  </code></pre>
  
  <p>[TS] Type alias ImmutableTreeData circularly references itself</p>
  
  <p>How can I fix this TypeScript error?</p>