What is the best/common way to cast a JSON into a class in Typescript with ES5 (no Object.assign()
).
e.g.
export class Lesson{
name:string;
teacher:Teacher;
date:Date;
scholars:Array<string>; //or string[] ... I dont care
}
The JSON would look like:
{
name:"LessonName",
teacher:{name:"masterT", age:120},
date:12345678912
scholars:["Jim","Bob","Jimbo"]
}
In Typescript I can cast the JSON to a Object and even assign it straight to a Lesson object (!-horrible behaviour, but thats JS-!)
But the object don't have any methods for example.
e.g. So lesson.date.getTime()
won't work.
So how to handle that correctly?