In my quest to create a function signature in Typescript, I am looking to develop a calling function that takes an object, its method name, and arguments to be applied.
Here is an example of it in action:
const obj = {
do(...args) {
console.log(args);
}
}
call(obj, 'do', 1, 2, 3);
I've been pondering on a simple signature that would specify the second parameter as a property of the first object. However, I find it challenging to restrict all properties that are not methods and clarify that variadic arguments should be passed as this method's arguments.
function call<T, P extends keyof T, A extends any[]>(obj: T, property: P, ...args: A): void;
Do you think it is achievable with the current version of Typescript?