I have the following base class:
export default class BaseModel{
Id:string;
CreatedDate:Date;
}
With following child class:
export default class ProfileModel extends BaseModel{
UserName:string;
Email:string;
Password:string;
FirstName:string;
LastName:string;
Vendor:Boolean;
Authenticated:Boolean;
constructor(aUserName, anEmail, aPassword, aFirstName, aLastName,
aVendor, isAuthenticated){
super();
this.UserName = aUserName;
this.Email = anEmail;
this.Password = aPassword;
this.FirstName = aFirstName;
this.LastName = aLastName;
this.Vendor = aVendor;
this.Authenticated = isAuthenticated;
}
public static NewNonVendor(aUserName, anEmail, aPassword, aFirstName,
aLastName):ProfileModel{
return new ProfileModel(aUserName, anEmail, aPassword, aFirstName,
aLastName, null, false);
}
}
I would like to move the fromJSON method to base class to handle serialization for all child classes. I want to basically do the following but having trouble coming up with the correct syntax:
export default class BaseModel<T>{
Id:string;
CreatedDate:Date;
static fromJSON(d: Object): T {
return Object.assign(new T(), d);
}
}