Task was to include an additional property.
I modified a current class by adding a new property, but when I assign a JSON object from the database, the newly added property disappears. Is there a way to correctly assign a JSON object to a TypeScript class so that the instance retains all properties and prevents data binding errors? I'm trying to avoid writing extra code to manually check the JSON...
Any assistance is appreciated
Example:
let JSONObject = {
FirstName: "Json",
LastName: "Born"
};
class Person {
FirstName: string = "Jason";
MiddleName: string = "Unknown";
LastName: string = "Bourne";
}
let PersonA = new Person();
console.log(PersonA); **//{FirstName:"Jason", MiddleName: "Unknown", LastName: "Bourne"}**
PersonA = JSON.parse(JSON.stringify(JSONObject));
//also tried **PersonA = <Person>JSON.parse(JSON.stringify(JSONObject));**
console.log(PersonA); **//{FirstName:"Json", LastName: "Born"}**
Attempted searching for solutions on converting a JSON object to a TypeScript class,