Let's say a simple overloaded function defined as the following:
function f(p: number) : string;
function f(p: string) : undefined;
function f(p: number | string): number | string {
return (typeof p === 'number') ? String(p) : undefined;
}
Parameters<typeof f>[0] gives me only string. Because it's the last overload defined.
How to choose which overload function to get the parameters from ?
Without having to reorder the definitions of course.
Note that we didn’t make b optional here because the return types of the signatures differ. Like so, since mines have differents returns types, this is not a problem at all.