我正在try 找出一种类型安全的方法来将函数及其参数(无论参数的数量是多少)传递给TypeScrip中的另一个包装函数.我想实现的目标是:
const myFunc1 = () => {...};
wrapper(myFunc1);
const myFunc2 = (a: string) => {...};
wrapper(myFunc2, 'hello');
const myFunc3 = (a: string, b: number) => {...};
wrapper(myFunc3, 'hello', 10);
以下是我的try :
function wrapper<A extends (...params: B[]) => any, B extends any>(x: A, ...y: B[]) {}