For example, if we have a Person object defined like this:
class PersonClass implements Person {
private _name : string;
private _age : number;
get name() : string {return this._name}
get age() : number {return this._age}
constructor(name : string, age : number) {
this._name = name;
this._age = age;
}
}
And we have an interface with the public properties:
interface Person {
name : string;
age : string;
}
If we want to get an object that matches the Person interface, it should look like this:
{ name: John, age: 23}
Is there a way to achieve this? I have tried casting ( person as Person
), JSON.stringify, and object assign, but I keep ending up with an object that includes the private data _name
and _age
, instead of the interface members name
and age
.