Skip to content

incorrect this and class instance with inheritation #12097

Description

@e-cloud

TypeScript Version: 2.1.0-dev.20161107

Code

{
  ...
  "compilerOptions": {
    "target": "es5"
  }
  ...
}
class WebpackOptionsValidationError extends Error {
    constructor() {
        super();
        Error.captureStackTrace(this, WebpackOptionsValidationError);
        this.name = 'WebpackOptionsValidationError';
    }
}

Expected behavior:

const err = new WebpackOptionsValidationError()
err instanceof WebpackOptionsValidationError // true

transpiled:

__extends(WebpackOptionsValidationError, _super);
function WebpackOptionsValidationError() {
    _super.call(this);
    Error.captureStackTrace(this, WebpackOptionsValidationError);
    this.name = 'WebpackOptionsValidationError';
    return this;
    // here return instance of WebpackOptionsValidationError
}

Actual behavior:

const err = new WebpackOptionsValidationError()
err instanceof WebpackOptionsValidationError
// false -- err is instanceof Error but not WebpackOptionsValidationError

transpiled:

__extends(WebpackOptionsValidationError, _super);
function WebpackOptionsValidationError() {
    var _this = _super.call(this) || this;
    Error.captureStackTrace(_this, WebpackOptionsValidationError);
    _this.name = 'WebpackOptionsValidationError';
    return _this;
    // here return instance of Error,
    // it refers to the prototype object of WebpackOptionsValidationError
}

The wrong behavior is result from #11846 and #11868.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions