I want to create a new function from an initial function, with the initial function taking a single object argument and the new function taking the same single object argument apart from populated fields. I've got something like this so far:
function returnNewFunc<TArg extends { b?: string }>(
initialFunc: (arg: TArg) => void
) {
const newFunc = (arg: Omit<TArg, "b">) =>
initialFunc({ ...arg, b: "hello" });
return newFunc
}
const funcA = ({ b, c }: { b: string; c: string }) => {
console.log(b, c);
};
const funcB = returnNewFunc(funcA)
funcB({c: "test"}) // funcB should have 'c' as the only field in its argument
The issue here is I get a could be instantiated with a different subtype of constraint typescript error, so I must be doing something wrong.