问题
Given a function that returns a factory, how can I annotate the function/factory so that it contains the correct type definitions?
Here's my example:
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>
Is this possible in typescript or should I suggest it as a new feature?
来源:https://stackoverflow.com/questions/52931628/how-to-annotate-nested-functions-with-generic-type-arguments