You create a mapped type where all the properties from the source type have the method signature of the arguments you've received. Then you use `Pluck` to narrow that type to just the one property you care about.
type HasMethod<Type extends object, N extends keyof Type, PropertyType> =
Pick<{ [P in keyof Type]: PropertyType; }, N>;
You can declare that the object passed in be of a type that extends this synthetic type -- which is defined by the object we're passing in!
type FunctionCall1<A1, R> = (arg1: A1) => R;
function callMethod<
Name extends keyof T,
T extends HasMethod<T, Name, FunctionCall1<A1, R>>,
A1, R>(obj: T, name: Name, arg1: A1): R;
There's 7 generics to get a method that accepts up to 4 arguments. But *none of them* have to be specified when you invoke the function.
gist.github.com/chriseppstein/…
Do you have a function that needs to accept any possible value but find that the `any` type is just a fancy way to write bugs? Me too! That's why I use `whatever`!
1️⃣ Typescript doesn’t error out if you pass too many arguments to the function. Only if you pass too few or the wrong types.