Q:

Wrap function and preserve input and return types?

Is it possible to wrap a function like this and preserve types?
const example = (alpha: string): string => alpha + 'beta';
const wrappedFn = (fn: Function) => fn;

How can I pull the types out of fn and return the same input and return as the passed in function?

A:

You can preserve all input argument types (even if there are more args) using tuples in rest parameters:
const example = (alpha: string): string => alpha + 'beta';
const wrappedFn = <A extends any[], R>(fn: (...args: A) => R) => (...args: A): R => {
    console.log("executing");
    return fn(...args);   
};

wrappedFn(example)("a")

