mardi 25 octobre 2016

TypeScript - set artificial object to certain class

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 setting the obj.__proto__.constructor = clazz the right way? Or perhaps is there a construct in TypeScript that would do this in more future-compatible way?





Aucun commentaire:

Enregistrer un commentaire