How can function overloading be reused effectively in TypeScript?
Consider a scenario where a function is overloaded:
function apply(value: number): number;
function apply(value: string): string;
function apply(value: any): any {
return value;
}
Now, let's say there is another function that uses the apply function:
function apply2(value: number | string) {
return apply(value); // encountering 'No overloads matching this call' error here
}
const result = apply2(1);
Is it necessary to overload apply2 as well?
- The type of result should be number
- Using generics is not an option in this case (the example provided is simplified)