title: Typescript: type that is union of object keys can't be use as a key for this object
body: <p>I have a function that is called with one parameter. This parameter is object. This function is returning another object, which one property is value of passed to function object. I have problem when I'm trying to retrieve value of object, using obj[key] notation.</p>
  
  <p>I do understand, that key has to be proper type to be used like this. I can't use simple key as string, if in interface I don't have [key: string]: any. But that's not the issue. My key is union of strings that were keys in passed object: 'user' | 'name' etc.</p>
  
  <pre class="lang-js prettyprint-override"><code>interface Twitter&lt;T&gt; {
    name: T;
    user: T;
    sex: T extends string ? boolean : string;
  }
  interface Facebook&lt;T&gt; {
    appName: T;
    whatever: T;
    imjustanexapmle: T;
  }
  
  type TwFbObjKeys = keyof Twitter&lt;string&gt; | keyof Facebook&lt;string&gt;
  </code></pre>
  
  <p>My function looks like this:</p>
  
  <pre class="lang-js prettyprint-override"><code>public static getArrayOfObjects(
          queryParameters: Twitter&lt;string&gt; | Facebook&lt;string&gt;,
      ) {
          const keys = Object.keys(queryParameters) as TwFbObjKeys[];
          return keys.map((paramId) =&gt; ({
              paramId,
              value: queryParameters[paramId],
          }));
      }
  </code></pre>
  
  <p>I would expect, that using paramId which is type: <em>'name' | 'sex' | 'appName' | ...</em> as a key for object, that has this keys, wouldn't throw an error. But unfortunately I have error:</p>
  
  <p><strong>TS7053: Element implicitly has an 'any' type because expression of type 'name' | 'sex' | 'appName' | ... can't be used to index type Twitter | Facebook.
  Property 'name' does not exists on type Twitter | Facebook</strong></p>
  
  <p>I'm fighting with it for few hours now. Any idea how I can solve it?</p>