I have multiple functions with various argument types:
function foo(a: number) {...}
function bar(a: string) {...}
...
To tackle this, I want to define a TypeScript interface (or type) that can handle these scenarios:
interface MyInterface {
method: typeof foo | typeof bar;
args: Parameters<foo | bar>;
}
The goal is to ensure that if the method
provided is foo, TypeScript will raise an error if args
is passed as [string]
, since it should actually expect [number]
. Similarly, if method
is bar, then args
must be of type [string]
.
Ultimately, method
could represent any of the functions specified in the interface, with args
corresponding to the arguments required for that particular function.