I'm working on some code that involves defining classes like the following:
class Place {
next: Place;
get to() : Place {
return this;
}
}
let places : Place[]= [];
..
places[0].to.next = new Place();
Since there are many similar classes, I thought it would be useful to define the 'to' property on Object.prototype.
Object.defineProperty(Object.prototye,"to",{
get: function() {
return this;
}
});
However, during compilation, I encountered an error:
Property 'next' does not exist on type 'Object'
Is there a way in Typescript to return a subtype using an Object.prototype function or property?