I am wondering if there is a way to achieve instance of sample_2 to show only parent classes properties:
class Parent {
constructor(public name:string) {}
}
class Child extends Parent {
constructor(public name: string, public age:number) {
super(name)
}
}
const sample = new Child("Robin", 30)
console.log(sample)
const sample_2 = sample as Parent // my attempt to type cast
console.log(sample_2)
These two both logs:
[LOG]: Child: {
"name": "Robin",
"age": 30
}
What I want to have is:
[LOG]: Parent: {
"name": "Robin"
}