为带有一个参数的咖喱函数提供界面
interface CurriedFunction1<T1, R> {
(): CurriedFunction1<T1, R>
(t1: T1): R
}
如何声明该类型的泛型函数?
以下声明无效:
declare let myFunction: CurriedFunction1<T[], string> // Cannot find name 'T'.
declare let myFunction2:<T>CurriedFunction1<T[], string> // '( expected.
答案 0 :(得分:1)
感谢您的评论,我现在了解您要执行的操作!这是不可能的。当在接口中声明调用签名时,调用签名的类型参数列表是固定的,并且不支持将类型变量的通用量化添加到现有类型(例如CurriedFunction1<T[], string>
)中。最接近的可能是引入包装器函数,该包装器函数必须使用类型参数调用才能获得实际的CurriedFunction1
:
declare let myFunction: <T>() => CurriedFunction1<T[], string>