title: TypeScript: Getting the type of object key inside object itself
body: <p>First of all, sorry for the bad title. I really don't know how to describe the problem, and maybe that's why I haven't found a solution yet!</p>
  
  <p>Here's a small snippet demonstrating my problem:</p>
  
  <pre><code>type Type&lt;T&gt; = {
    key: keyof T,
    doStuff: (value: T[typeof key]) =&gt; void
  //                          ^^^
  // TS2034: Cannot find name 'key'.
  };
  </code></pre>
  
  <p>It's pretty straightforward what I'm trying to do (I hope). I've tried to solve this several times, but every time the parameter ended up being an union of all available types.</p>
  
  <pre><code>const Test: Type&lt;{ var1: string, var2: number }&gt; = {
    key: 'var1',
    doStuff: (value) =&gt; {}
  //          ^^^^^
  // (parameter) value: string | number
  };
  </code></pre>
  
  <p>I'd appreciate it a lot if somebody could help me with this one. If you need additional info about what I'm trying to do here, or what I've already tried, please let me know!</p>