I'd like to upcast an object of a subclass so that it's properties are exclusively that of its superclass, but I've had no luck finding any ways of going about this in JS, and a surprising lack of documentation on weather or not this is even possible, which makes me think more and more it's not, at least in a nice concise way.
The only question I could find on doing this in JS went unanswered and can be found here: How to upcast to limit object properties
Here is a minimal example of what I would like:
class A{
constructor(a){
this.a = a;
}
}
class B extends A{
constructor(a, b){
super(a);
this.b = b;
}
}
let a = new A(3); //{a: 3}
let b = new B(4, 5); //{a: 4, b: 5}
//let upcastB = upcast b to type A //upcastB = {a: 4}
In conclusion, I'd like to know if there is just some standard way to go about upcasting in JS or if the only way to do this is just create two objects of type A and B and remove the different keys from object b.