This project is read-only.


Typescript extends is broken


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 used is :
var __extends = this.__extends || function (d, b) {
    function __() { this.constructor = d; }
    __.prototype = b.prototype;
    d.prototype = new __();
This breaks static member inheritance which is mentioned in the specification.
(Try It)

This would would if we use the extends as per the documentation. (Try It)
Closed Jun 13, 2013 at 7:22 PM by RyanCavanaugh
Fixed in develop branch


michelemottini wrote Mar 18, 2013 at 3:03 PM

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

RyanCavanaugh wrote Mar 18, 2013 at 5:34 PM

Marking 'active'

ThomasBk wrote Apr 27, 2013 at 10:09 PM

Until this is fixed you can work around the issue by using:
class Child extends Parent {
  static member = Parent.member;

clausreinke wrote May 8, 2013 at 9:30 AM

According to the ES6 spec editor,
Yes ES6 has "class-side" inheritance. The ES5 equivalent for:

class Sub extends Super {
constructor() {/*constructor body */ }
method1 () {}
static method2 {}


function Sub() {/constructor body / }
Sub.proto = Super;
Sub.prototype = Object.create(Super.prototype);
Sub.prototype.method1 = function method1() {};
Sub.method2 = function method2 () {}; looks first looks for a own property on Sub, then on Super, etc.

Unfortunately, the TS playground still has trouble with __proto__, so we can't just shim our own __extends.