How can I make the following work as expected in Typescript?
export class ProxyObject<T> {
private _dataObject:T;
constructor(dataObject?:T) {
if (dataObject) {
this.dataObject = dataObject;
} else {
//create a new instance of the generic <T> here
this.dataObject = <T> new Object();
}
}
set dataObject(dataObject:T) {
this._dataObject = dataObject;
}
get dataObject():T {
return this._dataObject;
}
}
export class ClassA {
myCoolProperty = "My Cool Property";
}
When I do the following:
export class MyObject extends ProxyObject<ClassA> {
}
And then:
var obj = new MyObject();
obj.dataObject.myCoolProperty === undefined
None of the ClassA properties or functions exist on the dataObject inside the MyObject as I was expecting. For instance, I expected dataObject to have myCoolProperty.
I'm trying to write a ProxyObject class that when extended it's DataObject storage is typed as the generic.
Thanks!!