I am attempting to create a sequence of nested functions that can be linked together, with the final callback receiving a combination of all parent arguments. Here is an example of my current unsuccessful approach:
export type SomeHandler<T> = (args: T) => void;
type WithFooArgs = { foo: string }
const withFoo = <T,>(handler: SomeHandler<T & WithFooArgs>) => (args: T & WithFooArgs) => handler(args);
type WithBarArgs = { bar: string }
const withBar = <T,>(handler: SomeHandler<T & WithBarArgs>) => (args: T & WithBarArgs) => handler(args);
type WithZooArgs = { zoo: string }
const withZoo = <T,>(handler: SomeHandler<T & WithZooArgs>) => (args: T & WithZooArgs) => handler(args);
export default withFoo(withBar(withZoo((args) => {
// I want args to be type `WithFooArgs & WithBarArgs & WithZooArgs`
})));
The objective is to have multiple such chains that can be combined in various ways.