This piece of code encapsulates the essence of what I'm trying to achieve more effectively than words:
function A(a: string): string;
function A(a: number): number;
function A(a: any) { return a; }
function B<T extends number | string>(arg: T): T {
return A(arg); // TS error: No overload matches this call.
}
Is it possible to use A(num)
, A(str)
, but not A(num | string)
in this scenario?
Do you have any suggestions on how to resolve this issue?