title: How do I add the same property in all levels of a tree-like type definition in TypeScript?
body: <p>I need a type generic to do self reference. And the next deep level know what the type is.
  Even with an error in the typescript, <code>const v</code> knows how to identify each property.
  Importantly, it is necessary to have N levels. Perhaps it would be simpler than I am thinking?</p>
  <pre><code>type RemoveArray&lt;R&gt; = R extends (infer U)[] ? U : R;
  
  type Base&lt;R&gt; = RemoveArray&lt;R&gt; &amp; {
    blabla: string
    data?: Base&lt;RemoveArray&lt;R['data']&gt;&gt;[]
  }
  type BaseArray&lt;R&gt; = Base&lt;R&gt;[]
  
  //------
  
  type Level2 = {
    d: string
    e: number
    //f:Level3[]
  }
  
  type Level1 = {
    a: string
    b: string
    data: Level2[]
  }
  
  const v: BaseArray&lt;Level1&gt; = [{
    a: 'a',
    b: 'b',
    blabla: 'lalala',
    data: [
      { blabla: 'lala', d: 'd', e: 'e' }
    ]
  }]
  </code></pre>
  <p><a href="https://www.typescriptlang.org/play?ts=4.2.3#code/C4TwDgpgBAShC2B7AbhAggJwwQxAHhgD4oBeWKCAD2AgDsATAZygAoBLWgMwgygFUAlAG0AulAD8-KAC5YAbgBQC0JCgAhbIwgFiZOElSYc%20IlABkUAN4KoUAEYAbbI%20yzGwDBwDmNqPWzA2OKyGloECCjoWLgEQgDk-oFxIoSEogoAvsrg0KFRxjqk6praROkKAPQVALS1dUoq0AAyEKgOAExF1rb0bh7evhCytACu8HY8vlWc0i1tAMzpWdmqcxAOAIxdvq5Q7p60PrZ2fQdHfgG7ax1LSgDGiLTuUMghJUYx1xu6UELdULs4tg4gAaXwnKBxOyg8FOFyyOJOJHAsE9S6yIS%20WyWexwpwI5GgvwI%20hEoaQiBxKBZWwiTIiIA" rel="nofollow noreferrer">Playground</a></p>