This project is read-only.

Generic improvement

Topics: General, Language Specification
Jul 17, 2013 at 10:54 AM
In the future do you think this would be possible :
interface IFace<T> extends T {

function foo<T, U, (R extends T,U)>(...) { 


It could help to map more extisting javascript library, and to create some kind of mixin model.
Jul 18, 2013 at 11:35 PM
So this would be like saying "R must have the features of T and U"? I could see that being handy.

As for mixins in general, I suspect we're going to be looking at them for future versions of TypeScript, since they are a pretty popular methodology.
Jul 19, 2013 at 12:27 PM
Edited Jul 19, 2013 at 12:35 PM
Yes that exactly what i meant.
And for mixins it would make possible to do something like that :
function applyMixin<T, U, (R extends T,U)>(instance:T, mixin:{new ():U;}):R {
    var properties = Object.getOwnPropertyNames(mixin.prototype);
    for(var i = 0, l = properties.length; i < l; i++) {
        var property = properties[0],
            propertyDescriptor = Object.getOwnPropertyDescriptor(mixin.prototype, property);
        Object.defineProperty(instance, property, propertyDescriptor);
    return <R>instance;

class A {

class B {

var instance = new A(),
    mixedInstance = applyMixin(a, B);