Skip to content

Incorrect transpiled constructor of derived classes #12123

Description

@falsandtru

TypeScript Version: master

Code

classCextendsError{constructor(){super('error');}m(){}}console.log(newC().message);console.log(newC().m);console.log(newC()instanceofError);console.log(newC()instanceofC);

Expected behavior:

var__extends=(this&&this.__extends)||function(d,b){for(varpinb)if(b.hasOwnProperty(p))d[p]=b[p];function__(){this.constructor=d;}d.prototype=b===null ? Object.create(b) : (__.prototype=b.prototype,new__());};varC=(function(_super){__extends(C,_super);functionC(){var_that=_super.call(this,'error');if(_that){_that.__proto__=this;}var_this=_that||this;return_this;}C.prototype.m=function(){};returnC;}(Error));console.log(newC().message);// 'error'console.log(newC().m);// [Function]console.log(newC()instanceofError);// trueconsole.log(newC()instanceofC);// true

Actual behavior:

var__extends=(this&&this.__extends)||function(d,b){for(varpinb)if(b.hasOwnProperty(p))d[p]=b[p];function__(){this.constructor=d;}d.prototype=b===null ? Object.create(b) : (__.prototype=b.prototype,new__());};varC=(function(_super){__extends(C,_super);functionC(){return_super.call(this,'error')||this;}C.prototype.m=function(){};returnC;}(Error));console.log(newC().message);// 'error'console.log(newC().m);// undefinedconsole.log(newC()instanceofError);// trueconsole.log(newC()instanceofC);// false

Metadata

Metadata

Assignees

No one assigned

    Labels

    Breaking ChangeWould introduce errors in existing codeCanonicalThis issue contains a lengthy and complete description of a particular problem, solution, or designDesign LimitationConstraints of the existing architecture prevent this from being fixed

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions