I am writing a code that handles classes instantiation (unmarshaller).
First, I create an object. I do that using let obj = new BaseModel.
During processing of the input data, I eventually figure out the class of the unmarshalled object.
I have that class, in terms of <T extends BaseModel> clazz : { new (): T }.
Now I would like to change the class of the object created earlier, in a way that it doesn't collide with TypeScripts class handling code.
Is this the right way?
Object.getPrototypeOf(result).constructor = clazz;
Edit: This is not it. While the property value stays, the browsers console still show the type used with new.
Or perhaps is there a construct in TypeScript that would do this in more future-compatible way?