title: Retrieve nested value from nested typescript type using dotted string
body: <p>Is it possible to retrieve / update a nested value in a custom Typescript type using a dotted string?</p>
  <pre><code>interface IChild {
    childName: string;
  }
  
  interface IRoot {
    root: string;
    child: IChild;
  }
  
  const O:IRoot = {
    root: &quot;Root name&quot;,
    child: {
      childName: &quot;Child Name&quot;
    }
  }
  
  console.log(O['child.childname']); // Not allowed
  </code></pre>
  <p>Is there a way of accessing this prop using dotted notation?</p>
  <p>Edit: I have put this together to show how I am getting the value using dot notation from a nested type</p>
  <pre><code>    type Prev = [never, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
          11, 12, 13, 14, 15, 16, 17, 18, 19, 20, ...0[]];
  
      type Join&lt;K, P&gt; = K extends string | number ?
          P extends string | number ?
              `${K}${&quot;&quot; extends P ? &quot;&quot; : &quot;.&quot;}${P}`
              : never : never;
  
      type NestedKeyof&lt;T, D extends number = 10&gt; = [D] extends [never] ? never : T extends object ?
          { [K in keyof T]-?: K extends string | number ?
              `${K}` | Join&lt;K, NestedKeyof&lt;T[K], Prev[D]&gt;&gt;
              : never
          }[keyof T] : &quot;&quot;
          
      const state: IRoot = {
          name: &quot;Root&quot;,
          child: {
              childname: &quot;Child1&quot;,
              grandchild: {
                  childname: &quot;Child2&quot;
              }
          }
      } as IRoot;
  
      const getProperty = &lt;P extends keyof T, T&gt;(o:T, p:P ) =&gt; {
          return o[p];
      }
  
      const getNestedProperty = &lt;P extends NestedKeyof&lt;T,3&gt;, T&gt;(o:T, p:P ): any =&gt; {
          const parts = String(p).split(&quot;.&quot;);
          let temp: any = getProperty(o, parts[0] as keyof T);
          parts.shift();
          parts.map(p=&gt; {
              temp = getProperty(temp, p as keyof typeof temp);
          })
          return temp;
      }
      
      console.log(getNestedProperty(state, &quot;child.grandchild.childname&quot;));
  </code></pre>
  <p>The magic seems to be that when you have an anonymous type you can type guard using</p>
  <p><code>keyof typeof anonymoustype</code></p>
  <p>So as you recurse the structure you can use this to satisfy typescript.</p>