Keep type information after compilation on generics

Topics: Language Specification
Jun 21, 2013 at 2:26 PM
It would be great to have some type information left after the compilation process on both generic types and methods. I would propose that types be passed as hidden parameters to the generic method/ class constructor. The information is already available at the call site so this would be pretty simple to accomplish.

This would enable scenarios, like creating new objects of the generic type.
class Greeter<T> {
    greeting: T;
    constructor(message: T) {
        this.greeting = message;
    }
    greet() {
        return this.greeting;
    }
    create<U>():U
    {
        return new U();
    }
}
could be compiled as
var Greeter = (function () {
    function Greeter(T, message) {
        this.T = T;
        this.greeting = message;
    }
    Greeter.prototype.greet = function () {
        return this.greeting;
    };
    Greeter.prototype.create = function (U) {
        return new U();
    };
    return Greeter;
})();