class Parent {
protected info: any;
getInfo(): dataTypeA | dataTypeB {
return this.info;
}
}
class A extends Parent {
protected info: dataTypeA = getDataTypeA();
}
class B extends Parent {
protected info: dataTypeB = getDataTypeB();
}
How can we modify the a.getInfo()
and b.getInfo()
methods to specifically return dataTypeA
and dataTypeB
respectively, instead of the current union type dataTypeA | dataTypeB
, assuming that a
and b
are instances of classes A
and B
?