title: Typescript: method signature based on generic
body: <p>I've the following generic class:</p>
  <pre class="lang-js prettyprint-override"><code>export class AClass&lt;Data = void&gt; {
  
  refresh(data: Data): void {}
  
  }
  </code></pre>
  <p>I would like the signature of the refresh method to be:</p>
  <pre class="lang-js prettyprint-override"><code>refresh(){} // when Data = void
  </code></pre>
  <pre class="lang-js prettyprint-override"><code>refresh(data: Data){} // otherwise
  </code></pre>
  <p>I do not want to make the data argument optional</p>
  <pre class="lang-js prettyprint-override"><code>refresh(data?: Data){} // not what I want because if data is different than &quot;void&quot; the arguments will be optional as well
  </code></pre>
  <p>The best I've been able to do is to use a variable holding a function instead of using a method.</p>
  <pre class="lang-js prettyprint-override"><code>export class AClass&lt;Data = void&gt; {
      refresh: Data extends void ? () =&gt; void : (data: Data) =&gt; void = (...arg){
          console.log(...arg);
      }
  }
  </code></pre>
  <p>I doubt we can have conditional method (class) signature defined within the same class, but is this accurate ?</p>
  <p>[EDIT]
  Why this question ?</p>
  <p>Here is a TS class:</p>
  <pre class="lang-js prettyprint-override"><code>class Example {
    aMethod () {
      console.log(`I am a method`)
    };
  
    aVariable = () =&gt; {console.log(`I am a variable holding a function`)}
  }
  </code></pre>
  <p>This will be transpiled into this:</p>
  <pre class="lang-js prettyprint-override"><code>&quot;use strict&quot;;
  class Example {
      constructor() {
          this.aVariable = () =&gt; { console.log(`I am a variable holding a function`); };
      }
      aMethod() {
          console.log(`I am a method`);
      }
      ;
  }
  </code></pre>
  <p>We can clearly while both will eventually achieve the same however the method one is closer to the &quot;native&quot; es6 method implementation.
  For this reason, I would like to find out if there is a way to type a class's method so that I will still be using a method instead of a variable.</p>