title: typescript multiple generics of the same type
body: <p>I have a lot of lists that need to be casted to maps so i decided to create a <code>listToMap</code> function:</p>
  
  <pre><code>export function listToMap&lt;T&gt;(
    list: T[],
    keyAccesFn: (listElement: T) =&gt; string): Map&lt;string, T&gt; {
    const reducer = (accumulator: Map&lt;string, T&gt;, currentValue: T) =&gt; accumulator.set(keyAccesFn(currentValue), currentValue);
    return list.reduce(reducer, new Map&lt;string, T&gt;());
  };
  </code></pre>
  
  <p>the function takes a list and a function which returns a string for a list element. The result is a Map with the returned string of <code>keyAccesFn</code> as key for the listelement the function was used on.</p>
  
  <p>Now it occured that i not only have to extract the Maps key of the listed Objects but the value itself. I decided to apporach this by passing another function into the listToMap function which <strong>might</strong> return a new Type. The function looks like this atm:</p>
  
  <pre><code>export function listToMap2&lt;T1, T2&gt;(
    list: T1[],
    keyAccesFn: (element: T1) =&gt; string,
    valueAccesFn: (element: T1) =&gt; T2 = (element: T1) =&gt; element): Map&lt;string, T2&gt; {
    const reducer = (accumulator: Map&lt;string, T2&gt;, currentValue: T1) =&gt; accumulator.set(keyAccesFn(currentValue), valueAccesFn(currentValue));
    return list.reduce(reducer, new Map&lt;string, T2&gt;());
  };
  </code></pre>
  
  <p>The <strong>issue</strong> is: i want to provide a default <code>valueAccessFn</code> that just returns the list elemnt so i could replace listToMap with <code>listToMap2</code>, but can't as typescript does not accept that generic type <code>T1</code> might be generic type <code>T2</code>. That annoys me espacially, as i have no other place where pass anything of <code>T2</code>. </p>