如何在打字稿中写出curried函数的类型签名

时间:2015-09-09 04:04:21

标签: typescript higher-order-functions

如何在打字稿中编写类似函数的类型签名?

var apply = (fn) => (list) => 
    fn.apply(null, list);

1 个答案:

答案 0 :(得分:2)

你走了:

var apply : (fn:Function) => (list:any[]) => any = (fn) => (list) => 
    fn.apply(null, list);

另一个样本:

var foo = (a:number) => (b:number) => (c:number) => {
    return a + b + c; 
};

var add1 = foo(1);
var add2 = foo(1)(1);

console.log(add1(1)(1)); // 3 
console.log(add2(1)); // 3