You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
class B extends A {
constructor(msg:string) {
super(msg);
}
}
class A {
constructor(public msg:string) {
}
}
Generates
var __extends = ... we've all seen this! :)
var B = (function (_super) {
__extends(B, _super);
function B(msg) {
_super.call(this, msg);
}
return B;
})(A);
var A = (function () {
function A(msg) {
this.msg = msg;
}
return A;
})();
The IIFE after var B = has a parameter of A, but var A = ...isn't called until just after that.
I don't know how you could get the above functionality ... maybe:
var B;
var A;
(function(){
function b(_super) {
__extends(B, _super);
function B(msg) {
_super.call(this, msg);
}
return B;
}
function a(){ ... }
B = b(a);
A = a;
})()
I am having the same issue even if the class is used after the other:
BaseClass.ts:
module MyModule {
class Base {
constructor() { }
}
}
ChildClass.ts:
module MyModule {
class Child extends Base {
constructor() { super(); }
}
}
Generates:
/****************************************************************************
Generated by T4TS.tt - don't make any changes in this file
****************************************************************************/
var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var MyModule;
(function (MyModule) {
/** Generated from MyModule.Base **/
var Base = (function () {
function Base () {
}
return Base;
})();
MyModule.Base = Base;
})(MyModule || (MyModule = {}));
var MyModule;
(function (MyModule) {
/** Generated from MyModule.Child **/
var Child = (function (_super) {
__extends(Child, _super);
function Child() {
_super.apply(this, arguments);
}
return Child;
})(MyModule.Base);
MyModule.Child = Child;
})(MyModule|| (MyModule = {}));
It seems that the order is correct, although it doesn't look like it is working as expected.
Rodrigo G. de Queiroz (@rodrigogq) the generated code you posted runs without error. The input code you posted has a compile error because Base is not exported from its module and is thus invisible in the second declaration.
Activity
mhegazy commentedon Aug 17, 2015
This issue has been discussed in #21 and has been closed for some bigger issue. this has been a reoccurring pain though.
The consensuses in #21 is to show a compiler error about what the wrong order. we should be able to do this easily using
checker.ts::isDefinedBefore.Add testcase for #4341
Reports error if class declaration appears before extended type decla…
nbellowe commentedon Aug 20, 2015
Why isn't this expected behavior?
Generates
The IIFE after
var B =has a parameter ofA, butvar A = ...isn't called until just after that.I don't know how you could get the above functionality ... maybe:
DanielRosenwasser commentedon Aug 20, 2015
It's expected, it's just that the compiler should warn you that this will happen.
danquirk commentedon Aug 20, 2015
As mentioned, dupe of #2854
mhegazy commentedon Aug 20, 2015
Sheetal Nandi (@sheetalkamat) has a fix for the class issue since it has been biting users quite frequently.
3 remaining items
rodrigogq commentedon Dec 14, 2015
I am having the same issue even if the class is used after the other:
BaseClass.ts:
ChildClass.ts:
Generates:
It seems that the order is correct, although it doesn't look like it is working as expected.
RyanCavanaugh commentedon Dec 14, 2015
Rodrigo G. de Queiroz (@rodrigogq) the generated code you posted runs without error. The input code you posted has a compile error because
Baseis not exported from its module and is thus invisible in the second declaration.mhegazy commentedon Feb 22, 2016
closing in favor of #5207
Fixing issues with TS generation
TypeScript generation fixes (#1047)