title: "This" used as return type in TypeScript?
body: <p>I was testing out method chaining and found that it can be accomplished using "this" as a return type?</p>
  
  <p>Here's an example:</p>
  
  <pre><code>class Shape {
      color: String;
  
      setColor(value: string): this { //Shape won't chain
          this.color = value;
          return this;
      }
  }
  
  class Square extends Shape {
      width: number;
  
      setWidth(value: number): Square {
          this.width = value;
          return this;
      }
  }
  
  function drawSquare(square: Square) {
      alert("width: " + square.width + "\ncolor: " + square.color);
  }
  
  let rect = new Square().setWidth(20).setColor("blue");
  drawSquare(rect);
  </code></pre>
  
  <p><a href="https://www.typescriptlang.org/play/#src=class%20Shape%20%7B%0D%0A%09color%3A%20String%3B%0D%0A%09%0D%0A%09setColor(value%3A%20string)%20%3A%20this%20%7B%20%2F%2FShape%20won&#39;t%20chain%0D%0A%09%09this.color%20%3D%20value%3B%0D%0A%09%09return%20this%3B%0D%0A%09%7D%0D%0A%7D%0D%0A%0D%0Aclass%20Square%20extends%20Shape%20%7B%0D%0A%09width%3A%20number%3B%0D%0A%09%0D%0A%09setWidth(value%3A%20number)%20%3A%20Square%20%7B%0D%0A%09%09this.width%20%3D%20value%3B%0D%0A%09%09return%20this%3B%0D%0A%09%7D%0D%0A%0D%0A%7D%0D%0A%0D%0Afunction%20drawSquare(square%3A%20Square)%20%7B%0D%0A%09alert(%22width%3A%20%22%20%2B%20square.width%20%2B%20%22%5Cncolor%3A%20%22%20%2B%20square.color)%3B%0D%0A%7D%0D%0A%0D%0Alet%20rect%20%3D%20new%20Square().setWidth(20).setColor(%22blue%22)%3B%0D%0AdrawSquare(rect)%3B" rel="noreferrer">Example in playground</a></p>
  
  <p>Is this the correct way of achieving method chaining when mixing base and inherited classes?</p>