title: Get return type from a map of generic functions
body: <p>I have the following dictionary where functions are polymorphic, accept the same argument but return different result:</p>
  <pre class="lang-js prettyprint-override"><code>const dict = {
    one: {
      foo&lt;A&gt;(a: A) {
        return [a] as const
      }
    },
    two: {
      foo&lt;A&gt;(a: A) {
        return [a, a] as const
      }
    },
    three: {
      foo&lt;A&gt;(a: A) {
        return [a, a, a] as const
      }
    }
  }
  
  type Map = typeof map
  </code></pre>
  <p>I'd like to get the function's return type from that dictionary, with the following helper:</p>
  <pre class="lang-js prettyprint-override"><code>const wrapper = &lt;N extends keyof Map, A&gt;() =&gt; {
    const fn = (() =&gt; {}) as unknown as Map[N]['foo']
    return null as unknown as ReturnType&lt;typeof fn&lt;A&gt;&gt;
  }
  </code></pre>
  <p>Trying to get the result <em>(For instance, what function named <code>two</code> will return if I'll pass <code>7</code> as the first argument)</em>:</p>
  <pre class="lang-js prettyprint-override"><code>// returns: &quot;readonly [7] | readonly [7, 7] | readonly [7, 7, 7]&quot;
  // expected: &quot;readonly [7, 7]&quot;
  type Result = typeof wrapper&lt;'two', 7&gt;
  </code></pre>
  <p>The problem is that I get the result as a union containing return types from all functions instead of the result for the function <code>two</code>.</p>
  <p>Seems like the generic <code>N</code> argument of a <code>wrapper</code> function is considered as a union even if I pass only one value as an argument.</p>
  <p>How can I get the correct result? The complication is that I do not have access to the <code>dict</code> object since it's coming from the library.</p>
  <p><a href="https://www.typescriptlang.org/play?#code/MYewdgzgLgBAJgS2LAvDA3gWAFAxuAUwC4Mc88AzEEAHgEEA%20ACgEMS6BKU3cvAJwJQArnzAwA2iwC6MFhBihIUMuQC%20K1QBoVUAO4gSWHpWr1mbGJ269%20gkWMmbZMuQvDQVedTy06AFgLE1uRUtIys7FxGNjACwqISLE5JzrLyih7GMN5eON44UACeAA4EMAAiSKgwRaUgFPBVODgZsLp8LMWlfDBoNAByMAQAHlAEYHDyANYEhfUVVU7hXCgMwa0wFGJoTEwra%20iqXK5CYFNgILpirpXI4v1S4gDkoU9SKnH2MGBCADa-aRgp3Ol2u8gASnZRAAVEoEGi1AjzLZmBh5ZrYAD0mNiUMgJAARAIWHBwL9ChIAOwyAA%20uJJZIp4kpTmpMDpxNJYHJVNZrKkBJw2KGw1KyAIcEJnMZvJg1MF2ERMEhED%201Uh8TAsNKCLh83anW6NCeehAT1ZDAYQA" rel="nofollow noreferrer">Code at TS Playground</a> for the simplicity</p>