For example, suppose I'm writing a memoize function, which accepts a function and returns another function. I want to leverage TypeScript so that the output function is guaranteed to have the same type as the input function, even though I don't know the type of the input function in advance. Here's some example code:
function wrap(fn) {
return function(...args) {
return fn(...args);
};
}
function repeat1(a: string, b: number): string {
return a.repeat(b);
}
const repeat2 = wrap(repeat1);
Unfortunately, repeat2 resolves to the type (...args: any[]) => any. I can't seem to find a way to express the wrap function in such a way that propagates the input type to the output type.