title: Pick value from object with dynamic key based on input key in Typescript
body: <p>So my backend has a JSON like this</p>
  <pre><code>name: &quot;Hello&quot;,
  nameTranslations: {nl:&quot;Hallo&quot;, en: &quot;Hello&quot;, fr: &quot;Bonjour&quot;}
  description: &quot;Hello&quot;,
  descriptionTranslations: {nl:&quot;Hallo&quot;, en: &quot;Hello&quot;, fr: &quot;Bonjour&quot;}
  </code></pre>
  <p>I want to build a function where I'll put in the object and key and it will automatically find the best translation possible. It's easy in Javascript but I want to get Typescript right so I won't be dealing with runtime bugs if I forgot to query the translations (I use GraphQL)</p>
  <pre class="lang-js prettyprint-override"><code>function getText(object, key, language) {
    const best = object[`${key}Translations`][language];
    if (best) {
      return best;
    }
  
    return object[key];
  }
  </code></pre>
  <p>Some Typescript requirements I have</p>
  <ul>
  <li>I want only the keys possible of the input object</li>
  <li>I want Typescript to return an error if the key is not available on the object or the 'keyTranslations'</li>
  </ul>
  <p><strong>Update</strong>
  <s>
  Based on the answer of @michmich112 I did go with the following function</p>
  <pre class="lang-js prettyprint-override"><code>function translate&lt;T extends BackendTranslations&gt;(translations: T, fallback: string, language: keyof BackendTranslations) =&gt; {
        return translations[language] || fallback;
  }
  
  translate(project.nameTranslations, project.name)
  
  </code></pre>
  <p>I will keep the answer open, since I'm still interested if this could work in Typescript
  </s></p>