I'm trying to remove the first argument from a function with multiple overloads.
I've used the type below from this Stack Overflow answer to do this for functions without overloads but am having some trouble to get it to work with overloads.
type OmitFirstArg<F> = F extends (x: any, ...args: infer P) => infer R ? (...args: P) => R : never;
Example:
function func1(arg1: any, arg2: string): string;
function func1(arg1: any, arg2: number): number;
function func1(arg1: any, arg2: string | number): string | number {
...
}
type Func2 = OmitFirstArg<typeof func1>;
In this example type Func2 = (arg2: number) => number
.
I need it to be:
type Func2 = {
(arg2: string): string;
(arg2: number): number;
}