3

The specification mentions that the following function will be used for extension :

var __extends = this.__extends || function(d, b) {
    for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
    function f() { this.constructor = d; }
    f.prototype = b.prototype;
    d.prototype = new f();
}

However the function generated currently is :

var __extends = this.__extends || function (d, b) {
    function __() { this.constructor = d; }
    __.prototype = b.prototype;
    d.prototype = new __();
};

This breaks static inheritance:

class A{
    fooMem=10;
    static fooStat=10;
}
class B extends A{};

var b = new B();
alert(b.fooMem.toString());
alert(B.fooStat.toString());

Try It

Which would work if the documentation mentioned extends function is used : Test

Anybody know the reason why the documentation mentioned function was not used?

3
  • typescript.codeplex.com/workitem/825 Commented Mar 18, 2013 at 4:12
  • The TypeScript compiler does not think that class B has a static member fooStat - that seems wrong reading the specs, but the generated JavaScript matches what the compiler thinks at least. Commented Mar 18, 2013 at 14:01
  • 1
    Thanks for identifying this and providing a manual solution for us in the mean time. This was making me crazy. Commented Apr 12, 2013 at 15:44

1 Answer 1

2

It has been accepted as a bug: http://typescript.codeplex.com/workitem/825

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.