title: Type narrowing a deeply nested object
body: <p>I'm trying to drill down through an unknown shaped object at runtime. What I'm confused about is that I'm getting an <code>Unsafe member access .errors on an any value</code> error on all the references below <code>if (typeof err.response?.data === &quot;object&quot;)</code>. However, shouldn't data be narrowed at that point to an object which has an errors property?</p>
  <pre><code>const getApiError = (err) =&gt; {
    if (axios.isAxiosError(err)) {
      if (typeof err.response?.data === &quot;object&quot;) {
        if (&quot;errors&quot; in err.response?.data)
          if (
            Array.isArray(err.response?.data.errors) &amp;&amp;
            err.response?.data.errors.length &gt; 0
          ) {
            return err.response?.data.errors[0] as ApiError
          }
      }
    }
    return null
  }
  </code></pre>
  <p>Also, if there's a more elegant way to drill down through objects like this, I'm all ears.</p>