title: Typescript function overloading - No overload matches this call
body: <p>I'm writing a function that calls another function that have enums as accepted parameters. Depending on the value passed, the return type from the function differs.</p>
  <p>The function being called (b) and function calling (a) will both need to have their parameters conforming to the enum. I wonder why the following code gives a Tyepscript error?</p>
  <pre><code>export function a (mode: 'a' | 'b') {
     return b(mode)
  }
  export function b (mode: 'a'): string
  export function b (mode: 'b'): number
  export function b (mode: 'a' | 'b'): string | number {
     return (mode=='a') ? 'string' : 1;
  }
  </code></pre>
  <p>Error:</p>
  <pre><code>  No overload matches this call.
    Overload 1 of 2, '(mode: &quot;a&quot;): string', gave the following error.
      Argument of type '&quot;a&quot; | &quot;b&quot;' is not assignable to parameter of type '&quot;a&quot;'.
        Type '&quot;b&quot;' is not assignable to type '&quot;a&quot;'.
    Overload 2 of 2, '(mode: &quot;b&quot;): number', gave the following error.
      Argument of type '&quot;a&quot; | &quot;b&quot;' is not assignable to parameter of type '&quot;b&quot;'.
        Type '&quot;a&quot;' is not assignable to type '&quot;b&quot;'.ts(2769)
  Cart.tsx(118, 18): The call would have succeeded against this implementation, but implementation signatures of overloads are not externally visible.
  </code></pre>
  <p>Closest question is <a href="https://stackoverflow.com/questions/58419985/typescript-function-overloading-no-overload-matches-this-call">here</a>, but I don't want to have a signature that is ambiguous - mode 'a' should always return string, and 'b' always number.</p>