title: How to type a subproperty of a nested object?
body: <p>I know this sounds like a generic question, but I wasn't quite able to find an answer online.</p>
  <p>Suppose I have the following object,</p>
  <pre><code>const myObject = {
      property: {
          subProperty: null
      },
  }
  </code></pre>
  <p>The following works just fine:</p>
  <pre><code>const getValue = (): string =&gt; 'property'
  
  const value = myObject[getValue() as keyof typeof myObject]
  </code></pre>
  <p>However when I try to type the <code>subProperty</code> value, I get an error. Here's how I try typing it:</p>
  <pre><code>const getValue = (): string =&gt; 'property'
  const getSubValue = (): string =&gt; 'subProperty'
  
  const value = myObject[getValue() as keyof typeof myObject]
  
  const subValue = myObject[getValue() as keyof typeof myObject][getSubValue() as keyof typeof myObject[getValue() as keyof typeof myObject]]
  </code></pre>
  <p>I'm aware that I can change the two methods to the following:</p>
  <pre><code>const getValue = (): 'property' =&gt; 'property'
  const getSubValue = (): 'subProperty' =&gt; 'subProperty'
  </code></pre>
  <p>This will work without the <code>keyof typeof</code> indicator, but obviously I need to keep the return value of the two functions to be <code>string</code>.</p>