title: Typescript Typecast
body: <p>I receive some JSON which can be a TextField object or a DateField object. Both inherit the Field superclass. The JSON I receive is converted to a Field object. I then need to cast this Field object into the corresponding type. To do this, I have an Id inside the JSON which lets me know if it's a TextField or DateField object. Everything works if I create a new TextField object and assign him the values of the JSON manually. However, I'd like to cast it directly to the corresponding class as it has the same attributes as the JSON. Something like <code>newField = &lt;TextareaField&gt;field;</code> but then, if I do <code>newField instanceof TextField</code>, it doesn't work. Any idea on how to cast an object to another type?</p>