title: Typescript: generic return type based on function paramenter
body: <p>Im trying to make a generic function that eventually makes a graphql query based on a &quot;selectedFields&quot; input to select specific fields of a full entity.</p>
  <p>Ive made the type of &quot;selectedFields&quot; to be an array of keys of the generic type which is how the entity looks on the db table.
  Now i want the result to have a type based on selectedFields.
  Is it possible by any chance?
  The code looks like that:</p>
  <pre><code>type KeysOf&lt;T&gt; = Extract&lt;keyof T, string&gt;[];
  
  function query&lt;DBEntity&gt;(
      tableName: string,
      queryName: string,
      selectedFields: KeysOf&lt;DBEntity&gt;,
  ) {
      return this.apolloLink.execute({
          query: gql`
              query ${queryName} {
                  ${queryName}: ${tableName} {
                      ${selectedFields.join('\n')}
                  }
              }
          `
      }).map(
          result =&gt; result?.data[queryName] as ???
      );
  }
  </code></pre>
  <p>NOTE: The &quot;DBEntity&quot; generic type is supposed to be a type for how the entity looks on db table
  for some logics i havent shown here on this function.</p>