Partial generic type specifier

Topics: Language Specification
Jun 7, 2014 at 5:17 PM
Is it possible to specify partial generic type as it possible in some other languages ?
This is sometimes useful if you want other type then the inferred one.
class A<T> {}
class B<T> extends A<T>{}

var b : A<_> = new B<number>();
function f<A,B>(a : A, b : B) : void {}

f<number, _>(1, 2);
Jun 9, 2014 at 3:38 AM
You cannot create partial classes. You can. however, create partial interfaces (so to speak - interfaces can be extended naturally).
Jun 9, 2014 at 4:19 AM
It is not about partial classes.
I talk about partially specify the generic type.
Now you have two choices either leave it and use compiler's type inference or specify a full type.
If you want an interface type, then it must be fully specified including all generic parameters.

I suggest an option that allows partially specifying the generic parameters whether to make a code clearer or use the more specific type.
Some programming languages support this, there is no reason for TypeScript to not support it.
Jun 9, 2014 at 6:37 AM
Ok, I see now what you mean. There is a request for default type arguments (, but it would be nice to allow specifying partial arguments, and allow inferring the rest. I recall myself also in a small situation where I wanted to specify a lambda expression for the first generic type, and have the second one inferred.