title: TypeScript function signature identical to passed in function's signature
body: <p>I'm working on a class to which the user passes in a method that takes a user-defined argument, or no argument. The class exposes a "call" method that must be called with the argument requested in the user's method, performs various operations, then calls the user's method and returns the result.</p>
  
  <p>This works fine if the user's function has an argument, but it breaks if the user's function doesn't use an argument.</p>
  
  <p>Here's my current code (I keep trying different variations but haven't figured out the correct one yet):</p>
  
  <pre><code>class Test&lt;T, TResult&gt; {
    methodToRun: (data?: T) =&gt; TResult;
  
    constructor(methodToRun: (data?: T)=&gt;TResult){
      this.methodToRun = methodToRun;
    }
  
    call(data: T) {
      // do some stuff, then...
      return data === undefined ? this.methodToRun(data) : this.methodToRun();
    }
  }
  
  const test = new Test(function(data: string){
    return 1;
  });
  
  test.call("");
  test.call(); // should be a signature error (currently is)
  
  const test2 = new Test(function(data: number){
    return 1;
  });
  
  test2.call(1);
  
  const test3 = new Test(function(data: {foo: string, bar: number}){
    return 1;
  });
  
  test3.call({foo: "", bar: 1});
  
  
  const test4 = new Test(function(){
   return 1;
  });
  
  test4.call(); // should be allowed (currently errors "Supplied Paramaters do not match any signature of call target")
  test4.call({}); // should not be allowed (currently is)
  </code></pre>
  
  <p>One of my attempted variations was to adjust the signature of call:</p>
  
  <pre><code>call()
  call(data: T) 
  call(data?: T) {
  </code></pre>
  
  <p>However that caused both test.call() and test4.call() to be allowed.
  How do I get typescript to ensure that the signature of call always matches the signature of the user's function?</p>