Currently, I am attempting to create a helper function that accepts an object of functions and wraps it in another function;
const bindFn = (obj, wrapFn) => Object.entries(obj).reduce((carry, [key, fn])=>{
carry[key] = ( ...args ) => wrapFn(fn.apply(null, args))
return carry;
},{})
// example of usage
const n = bindFn( { sum: (x) => x+1 }, console.log);
n.sum(3); // this should console.log 4
The issue is, I am unsure how to define the type for bindFn so that it returns the correct type that contains an object with the same keys and return types as the supplied object. Something like:
interface BindFn = {
[name: keyof obj] : () => ReturnType<obj[name]> :D !!! no clue.
}