How can we define the function getInterface
in a way that the returned type by res is specifically number
?
Just to be clear: I am not attempting to write these functions myself; rather, I have an environment where a method exists that returns different objects based on parameters.type, and I'm seeking a solution to properly type them.
interface A {
tag: 'a'
do_one: () => number;
}
interface B {
tag: 'b'
do_one: () => string;
}
type Interface = A | B
let one = getInterface({ type: 'a' })
let res = one.do_one()