title: TypeScript classes : constructor and method
body: <p>I am trying to avoid double declaration in my Typescript classes.</p>
  
  <p>Before I was writing my classes like that :</p>
  
  <pre><code>module ModuleName {
      export class ClassName {
          public method: () =&gt; void;
  
          constructor(
              private dependency: any ) {
              this.method = () =&gt; {
                  dependency.someUse();
              };
          }
      }
  }
  </code></pre>
  
  <p>But the declaration of the type of the method (here <code>public method: () =&gt; void;</code>) looks useless, especially when you already have an interface which declare it. So I wanted to write :</p>
  
  <pre><code>module ModuleName {
      export class ClassName {
          constructor(
              private dependency: any ) { }
  
          public method = () =&gt; {
              this.dependency.someUse();
          };
  
      }
  }
  </code></pre>
  
  <p>Note : To avoid warnings <code>variable XXX used before declaration</code>, we have to put the methods after the constructor.</p>
  
  <p>But now if we use our methods in the constructor, we again get the warnings on this methods :</p>
  
  <pre><code>module ModuleName {
      export class ClassName {
          constructor(
              private dependency: any ) {
              this.method(); // warning here
          }
  
          public method = () =&gt; {
              this.dependency.someUse();
          };
  
      }
  }
  </code></pre>
  
  <p>So, my question is : <strong>How should we write our classes properly ?</strong></p>
  
  <p><em>Note : As typescript compiler corrects the declaration's order, that's not a big deal, I just want to know if it's possible to write classes without double declarations and warnings.</em></p>