How do you map an instance of a derived class into an object which only contains the properties of it's base class?
interface Base {
a: string;
}
interface Derived extends Base {
b: string;
}
const derived: Derived = {
a: 'hello',
b: 'world'
}
const base: Base = derived;
console.log(base);
Output:
{ "a": "hello", "b": "world" }
Desired output:
{ "a": "hello" }
Sure I could do:
const base: Base = {a:derived.a};
But this would get very tedious for more complex classes.
What's the best way to do this programmatically in Typescript?