by aj0strow · 9y ago · 0 comments
The last feature I'd want is an easy way to map nested json into classes rather than interfaces. Anyone know how?
abstract class AbstractClassObject {
constructor(json?: any){
if (json){
this.updateFromJSON(json)
}
}
public updateFromJSON = (json: any): this => {
Object.assign(this, json);
return this;
}
}
That gives you the "magic" just by extending the base, while also allowing custom behavior for a given class (by overriding updateFromJSON). class Post {
id: string;
user: User; // <- should be typeof User
}
I was hoping for something like Golang json.Unmarshal.