I have two classes ClassA and ClassB as follow:
interface IClassA {
functionA: ()=> void
}
class ClassA implements IClassA{
functionA(){
console.log('hello world A')
}
}
interface IClassB {
functionB: ()=> void
}
class ClassB implements IClassB{
functionB() {
console.log('hello world B')
}
}
I have another function that needs to takes an instance of ClassA or ClassB as parameter as shown below.
function sayHello(object) {
// ...
}
How can I type the object in to access to the function functionA or functionB depending on the instance of the class being use? The code below won’t work:
function sayHello(object: IClassA | IClassB)
I don't want to use the generic any type. Thanks.
