title: determine callback function's signature in runtime
body: <p>I want to pass different callback functions as an argument and have them called with proper parameters.</p>
  
  <p>Here is a highly simplified example of how should it work. Except that <code>process instanceof ITwo</code> has no sense and I cannot find any expression that does the job.</p>
  
  <pre><code>    interface IOne { (j: string): number; }
      interface ITwo { (j: number): number; }
      function dualArg(i: string, process: IOne | ITwo): number {
          // something like this
          if (process instanceof ITwo) {
              // call with numeric arg
              return process(i);
          } else {
              // conver to number
              return process(+i);
          }
      }
      function inc(i: number): number {
          return ++i;
      }
      function idem(text: string): number {
          return +text;
      }
      it('determine function signature', () =&gt; {
          expect(dualArg('1', inc)).toBe(2);
          expect(dualArg('1', idem)).toBe(1);
      })
  </code></pre>
  
  <p>For a normal argument <code>instanceof</code> will be enough for TypeScript to treat it as an object of specific type, however there does not seem to be anything similar for functions.</p>
  
  <p>If I use some kind of hard-coded conditional, such as <code>process.prototype.constructor.name === 'idem'</code> I get Typescript error message: <code>Cannot invoke an expression whose type lacks a call signature. Type 'IOne | ITwo' has no compatible call signatures.</code></p>
  
  <p>Here of course I could define <code>process: any</code> to disable any TypeScript checks and the code will compile and run, but my goal is to be able to distinguish the functions just by their signature (and not rely on some other convention such as name or additional flags).</p>