I have a setup like the following:
enum Input {
A,
B,
C
}
function returnValue(input: Input) {
switch (input) {
case Input.A:
return 1;
case Input.B:
return 'B';
case Input.C:
return false;
}
}
let x = returnValue(Input.A);
I would like to map the different enum values of Input to different return types, so that when I call it with a given input I am given a specific type output. (in this case "X" would be number not string | number | boolean)
I know I can add function overloads like this
function returnValue(input: Input.A): number;
function returnValue(input: Input.B): string;
function returnValue(input: Input.C): boolean;
function returnValue(input: Input): number | string | boolean {
But I was hoping there was a "cleaner" solution, in my project there would be quite a lot of overloads here, so simply being able to map out Input.A: number somewhere would be far nicer if