title: Angular/typescript tree with child/parent references - how to avoid Block-scoped variable used before its declaration
body: <p>Lets have a tree of very simple nodes/objects with parents and children references, where we need to reference both, the parent and the children nodes. The tricky part here is that we do want to design and use the nodes not only in the tree but also independently from the tree/ separately. Meaning, we cannot nest them into the parent nodes directly, but by reference and also reference the child nodes in the parent nodes. That presents a problem of Typescript error:</p>
  
  <p><em>2448 Block-scoped variable 'rootNode' used before its declaration.ts(2448)</em></p>
  
  <p>If we place the nodes in descending order we can reference the children above. But not the parents below. And vice-versa. If we place parents above children, we cannot reference the children as they are declared after them. </p>
  
  <p>It appears that Typescript is not sophisticated enough to pre-compile declarations and throws errors instead.</p>
  
  <p>How can this be solved?</p>
  
  <p>Here is an example of the tree nodes (placed in descending order) and its '<em>independent</em>' nodes with references:</p>
  
  <pre><code>    export interface Node {
          id: string,
          value?: string,
          parent?: Node,
          children?: Node[]
      }
  
      export const nodeB2: Node = {
          id: 'B2',
          value: 'bbb-2',
          parent: nodeA1    // ERR 2448
      }
  
      export const nodeB1: Node = {
          id: 'B1',
          value: 'bbb-1',
          parent: nodeA1    // ERR 2448
      } 
  
      export const nodeA1: Node = {
          id: 'A1',
          value: 'aaa-1',
          parent: rootNode,    // ERR 2448
          children: [nodeB1, nodeB2]
      }
  
      export const rootNode: Node = {
          id: 'ROOT',
          value: 'root',
          children: [nodeA1]
      }
  </code></pre>