title: (Typescript) Setter is not called on a sub-property of a class instance
body: <p>this is a difficult question that I know is a problem for lots of programs (I will elaborate on this at the end). <strong>I want to create a custom setter in typescript but the datatype of the property being set is not just a number, string, bool it is actually a class object. This works fine - but if a property of the class instance is modified then the setter is not called</strong>. Here is an example of such a situation:</p>
  
  <pre><code>//This class contains two properties
  class Point
  {
      public x : number;
      public y : number;
  
      constructor(x : number, y : number) { this.x = x; this.y = 0; }
  }
  
  //How here is another class that contains a Point
  //But it is private and a getter/setter is used
  class PointStore
  {
      private _foo : Point;
  
      public get foo() : Point { return this._foo; }
  
      //Here is the problem, the setter is only called when the whole of foo is changed
      public set foo(n : Point) { this._foo = n; console.log("Foo has been set!"); }
  
      constructor() { this._foo = new Point(0, 0); }
  }
  
  //Use case
  let bar : PointStore = new PointStore();
  
  bar.foo = new Point(10, 10); //Logs "Foo has been set!"
  bar.foo.x = 20; //Doesn't log anything
  </code></pre>
  
  <hr>
  
  <p>The problem is pretty clear from the example but I just want to say the following:</p>
  
  <p><em>Is there anyway around this at all? Because I have seen from APIs such as Unity3D they have opted to make their 'Point' class have only private members and so data can only be set through the constructor</em> e.g:</p>
  
  <pre><code>//the 'Unity' solution
  transform.position = new Vector2(10, 10); //Okay
  transform.position.x = 20; //Error
  </code></pre>
  
  <p><em>But this is not at all a perfect solution to the problem, as it makes programming with the 'Point' class much more difficult from then on.</em></p>
  
  <p>If anyone has a trick to solve this, it would be greatly appreciated.</p>