title: How do I define a type rule on member values
body: <h2>Question</h2>
  <p>Lets say I have a <code>secretFunc</code> as such</p>
  <pre class="lang-js prettyprint-override"><code>const secretFunc = &lt;T extends object, TName extends keyof T&gt;({
    data,
    name
  }: {
    data: T
    name: TName
  }) =&gt; {
    const value = data[name]
    console.log(typeof value === 'number')
  }
  </code></pre>
  <p>As you can imagine, indifferent of the result, the typecheck is not at compile time.</p>
  <p><strong>How can I specify a rule such that <code>T[TName] is number</code> for compile time checking?</strong></p>
  <h2>My (Futile) attempt</h2>
  <p>This is the closest I could get...</p>
  <pre class="lang-js prettyprint-override"><code>type NumberHost&lt;T, TName extends keyof T&gt; = T[TName] extends number ? T : never
  
  const secretFunc = &lt;T extends object, TName extends keyof T&gt;({
    data,
    name
  }: {
    data: NumberHost&lt;T, TName&gt;
    name: TName
  }) =&gt; {
    if (data) {
      const value = data[name]
      console.log(typeof value === 'number')
    } else {
      console.log('no')
    }
  }
  
  secretFunc({ data: { label: 'five', value: 5 }, name: 'value' })
  </code></pre>
  <p>This causes compile errors when I use 'label' for <code>name</code> or when <code>value</code> is not a number. However, I am not convinced this is the best solution ☹️</p>