This is my interface hierarchy:
interface parent {
common: string;
}
interface child1 extends parent {
prop1: string;
}
interface child2 extends parent {
prop2: string;
}
My goal now is to create an interface with a property that is of type parent
, meaning it can be either child1 or child2.
My attempt was:
interface SomeObject {
member: parent;
}
let a: SomeObject = {
member: {
common: "a",
prop1: "b"
}
}
However, the compiler points out that prop1
is not a member of parent
.
What is the correct approach to achieve this?