title: Typescript union with dependent types
body: <p>If I have the following union which wraps a function and its argument, how can I call it?</p>
  <pre><code>type Wrapper = {
    fn: (a: string) =&gt; void
    arg: string
  } | {
    fn: (a: number) =&gt; void
    arg: number
  }
  
  let foo!: Wrapper
  foo.fn(foo.arg) // Error Type 'string' is not assignable to type 'never'.
  </code></pre>
  <p>I can't figure out how to call it. Everything that I've tried essentially boils down to a cast, (e.g. casting to <code>(a:any) =&gt; void</code>) which I can do if I have to, but I feel that I shouldn't have to do that.</p>
  <p>Can this function be called without casting?</p>
  <p>Edit: To clarify, I'm asking if there exist solutions which don't involve changing definition of <code>Wrapper</code>.</p>