title: Typescript: Avoid comparison by reference
body: <p>I need to store a list of points and check if a new point is already included in that list</p>
  
  <pre><code>class Point {
      x: number;
      y: number;
      constructor(x: number, y: number) {
          this.x = x;
          this.y = y;
      }
  }
  
  window.onload = () =&gt; {
      var points : Point[] = [];
      points.push(new Point(1,1));
      var point = new Point(1,1);
      alert(points.indexOf(point)); // -1 
  }
  </code></pre>
  
  <p>Obviously typescript uses comparison by reference but in this case that doesn't make sense. In Java or C# I would overload the <code>equals</code> method, in typescript that doesn't seem to be possible.</p>
  
  <p>I considered to loop through the array with <code>foreach</code> and check each entry for equality, but that seems rather complicated and would bloat the code.</p>
  
  <p>Is there something like <code>equals</code> in typescript ? How can I implement my own comparisons ?</p>