具有泛型的typescript函数变量

时间:2016-10-20 09:19:31

标签: generics typescript

如何将参数传递给保存函数的变量 -

export const filter = Curry(_filter) as ICurryFunction<T>

我收到错误 - Cannot find name T

filter常量存储函数。

Curry.ts

function Curry<T, R> (f: ICurryFunction<T>): ICurryFunction<T> {
  return function curried (...t: any[]): T | ICurryFunction<T> {
    if (t.length === 0) return curried
    if (t.length >= f.length) return f(...t)
    return curried.bind(this, ...t)
  }
}

ICurryFunction.ts

interface ICurryFunction<T> {
  (...k: any[]): T | ICurryFunction<T>
}

完整代码 https://github.com/tusharmath/observable-air/blob/master/src/main.ts#L24

0 个答案:

没有答案