给出一个返回工厂的函数,如何注释该函数/工厂,使其包含正确的类型定义?
这是我的例子:
class item<TA, TB> {
constructor(a: TA, b: TB) {
this.a = a;
}
a: T
}
function generate(c) {
return function a(a) {
return function b(b) {
return new c(a, b);
}
}
}
const factory = generate(item); // I want this to always be annotated as <TA, TB> (a: TA) => (b: TB) => item<TA, TB>
const partial = factory('string'); // instance should now be of type <TB> (b: TB) => item<string, TB>
const instance = partial('string'); // instance should now be of type item<string, string>
这可能是打字稿中的问题吗,还是应该将其推荐为一项新功能?