According to this answer (https://stackoverflow.com/a/52761156/599184), ReturnType<> doesn't work with overloaded functions in general. However, would it be possible to select a particular version of the overloaded function and get its return type?
The only way I can think of is to have code invoking the overloaded function.
function fn(arg: string): string;
function fn(arg: number): number;
function fn(arg: string | number): string | number {
return arg;
}
const temp1 = () => fn('string');
type Type1 = ReturnType<typeof temp1>; // string
const temp2 = () => fn(123);
type Type2 = ReturnType<typeof temp2>; // number
Is there a cleaner way where I don't have to pass in the arguments (just the argument type)?