I am curious how to create a typed function that allows you to pass the types of the function entered through as the return type and the arguments.
const preventDefault = function <T> (passThroughFunction: T) {
return function (event, ...args): ReturnType<typeof T> {
event.preventDefault();
return passThroughFunction(...[event, ...args]);
}
}
This is broken. I am not sure how to use ReturnType properly or extract the arguments from passThroughFunction and include them in the returned function.
So I can use it like this:
<Button onSubmit={preventDefault(onSubmit)}/>
How can I do this?