Let's dive into an example that involves strict null checking. Imagine I have the following function declaration:
declare function f(value: null, multiplier: number): null;
declare function f(value: string, multiplier: number): number;
declare function f(value: string | null, multiplier: number): number | null;
Now, I am looking to utilize it in this way:
const f2 = (value) => f(value, 2);
It appears that the inferred parameter type is "any" and the inferred return type is "number | null".
Is there a method to have TypeScript correctly infer the new function type so that it retains overloads without needing to redefine all signatures?
The desired call signature should match exactly with this:
function f2(value: null): null;
function f2(value: string): number;