title: How to do typescript function chaining?
body: <p>I want to use function chaining in <em>typescript</em>.</p>
  
  <p><strong>Consider a class</strong></p>
  
  <pre><code>export class numbOp(){
    private n;
    constructor(int num){
      this.n = num;
    }
  
    public add(inc = 1){
      this.n = this.n + inc;
    }
  
  }
  </code></pre>
  
  <p><strong>How do I use it as (1)</strong></p>
  
  <pre><code>let finalNumber = new numbOp(3);
  console.log(finalNumber) // Output: 3
  </code></pre>
  
  <p><strong>How do I use it as (2)</strong></p>
  
  <pre><code>let finalNumber = new numbOp(3).add();
  console.log(finalNumber) // Output: 4
  </code></pre>
  
  <p><strong>How do I use it as (3)</strong></p>
  
  <pre><code>let finalNumber = new numbOp(3).add().add();
  console.log(finalNumber) // Output: 5
  </code></pre>
  
  <p><strong>How do I use it as (4)</strong></p>
  
  <pre><code>let finalNumber = new numbOp(3).add().add(2).toString();
  console.log(finalNumber) // Output: "6"
  </code></pre>
  
  <blockquote>
    <p>Please, help me out to achieve this. Thanks in advance :)</p>
  </blockquote>