I'm trying to get the Parameters from an overloaded function
interface FuncContainer {
someFunc(name: string, value: number): number;
}
Here, I have an interface that has a function someFunc. What I'm really interested in is the type of value - this is pretty simple:
type Value = Parameters<FuncContainer["someFunc"]>[1]; // Value is type number
The problem is when using overloads, the last overload is always used by Parameters (via infer):
interface FuncContainer {
someFunc(name: string, value: number): number;
someFunc(name: string): number;
}
type Args = Parameters<FuncContainer["someFunc"]>; // [str: string]
type Value = Parameters<FuncContainer["someFunc"]>[1]; // undefined
I've tried leveraging extends with no effect:
type Parameter2<F extends (name: string, value: any) => any> = Parameters<F>[1];
type Value = Parameter2<FuncContainer["someFunc"]>; // undefined
Is there any way to specify which overload (by index, by type, whatever) is used when using Parameters?
someFuncbut it still picked the lower of the two (which madetype Value = ...equal tonumber.