title: Infer exact object property type when returning it via function
body: <p>Given the following state:</p>
  <pre><code>  type DataType = {
          a: string,
          b: number,
          c: boolean
    }
  
    const testObject: DataType = {
          a: 'Dummy',
          b: 1,
          c: true
    }
  
    type A = typeof testObject['a'] // string
    type B = typeof testObject['b'] // number
    type C = typeof testObject['c'] // boolean
  </code></pre>
  <p>It is clear that I can get the type of each property of the <code>DataType</code> object by using either <code>typeof testObject['a']</code> or <code>DataType['a']</code>.</p>
  <p><em>However,</em> when I try to do the same via accessor inside a function, I cannot get the exact type of the property I am accessing. Example below:</p>
  <pre><code>  function testAccess&lt;T&gt;(o: T, p: keyof T): T[typeof p] {
          return o[p]
    }
  
    const a = testAccess(testObject, 'a') // string | number | boolean
  </code></pre>
  <p>Am I missing something, and is there any way to narrow down the type to the exact key that we are sending?</p>
  <p>TS playground link: <a href="https://www.typescriptlang.org/play?jsx=0#code/C4TwDgpgBAIghsOAVc0C8UDeAoKf9wBcUAzsAE4CWAdgOYA0u%20eARsdQK4C2LE5jzPAGNiLAPZiANhDjVsAX2zZpwKMAhkA8iwBWEIcGLxEKSFAw5BUIlADkMblxC2BgtlACMr5iLXkOEApKoGYAguZqqGIAZmoawNp6BgDatnC2ALpQAPTZpBQ0tNgh0ABCESUxcVq6%20sCpLJk5eZw8fMWoUADCFVGx6jVJ9bZCTblQ4lIyckrRHNQGlGLU1cChQkIaJAA8SAB8ABRixEj0UGDEANYQIFVIAJQnyZWxYFmWguQQwBzkK2LJN5BbBCZZkawVeLrTYkEgHAYJWoGM5pWz3Zr5Kh0KAAHygrV45FxEwk0lkQA" rel="nofollow noreferrer">https://www.typescriptlang.org/play?jsx=0#code/C4TwD...</a></p>