I've found a strange bug.
If you have two classes in different files, and for example class B extends class A, and class A has a variable typed B, TypeScript compiles in wrong order with --out main.js command (when you compile whole project into one file). Wrond order results that javascript throws an error: Uncaught TypeError: Cannot read property 'prototype' of undefined This is because class B is earlier in the code than A, and it want to use it.
Here is the simpliest example:
A.ts
///<reference path='B.ts'/>
class A
{
public b: B;
constructor()
{
}
init()
{
this.b=new B();
}
}
B.ts
///<reference path='A.ts'/>
class B extends A
{
constructor()
{
super();
}
}
app.ts
///<reference path='A.ts'/>
var a: A=new A();
a.init();
Generated main.js
var __extends = this.__extends || function (d, b) {
function __() { this.constructor = d; }
__.prototype = b.prototype;
d.prototype = new __();
};
var B = (function (_super) {
__extends(B, _super);
function B() {
_super.call(this);
}
return B;
})(A);
var A = (function () {
function A() {
}
A.prototype.init = function () {
this.b = new B();
};
return A;
})();
var a = new A();
a.init();
//@ sourceMappingURL=main.js.map
Is there a workaround?