Skip to content

Cannot extend native type Error #12279

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
brodeuralexis opened this issue Nov 15, 2016 · 3 comments
Closed

Cannot extend native type Error #12279

brodeuralexis opened this issue Nov 15, 2016 · 3 comments
Labels
Duplicate An existing issue was already created

Comments

@brodeuralexis
Copy link

TypeScript Version: 2.1.1

Code

"use strict";

class Exception extends Error {

    public constructor(public status: number = 500, reason: string) {
        super(reason);

        if (!this.isValidStatus(status)) {
            this.status = 500;
        }
    }

    isValidStatus(status: number): boolean {
        return status >= 100 && status <= 599;
    }

}

const exception = new Exception(401, "Invalid API Key");

Expected behavior:
To see the program run to completion with any errors.

Actual behavior:

C:\Users\Consultant\issue.js:13
        if (!_this.isValidStatus(status)) {
                   ^

TypeError: _this.isValidStatus is not a function
    at new Exception (C:\Users\Consultant\issue.js:13:20)
    at Object.<anonymous> (C:\Users\Consultant\issue.js:23:17)
    at Module._compile (module.js:573:32)
    at Object.Module._extensions..js (module.js:582:10)
    at Module.load (module.js:490:32)
    at tryModuleLoad (module.js:449:12)
    at Function.Module._load (module.js:441:3)
    at Module.runMain (module.js:607:10)
    at run (bootstrap_node.js:382:7)
    at startup (bootstrap_node.js:137:9)

Additional Information:
This problem is only present in the release candidate (TypeScript@2.1.1).

Compiled JavaScript for TypeScript@2.1.1

"use strict";
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 Exception = (function (_super) {
    __extends(Exception, _super);
    function Exception(status, reason) {
        if (status === void 0) { status = 500; }
        var _this = _super.call(this, reason) || this;
        _this.status = status;
        if (!_this.isValidStatus(status)) {
            _this.status = 500;
        }
        return _this;
    }
    Exception.prototype.isValidStatus = function (status) {
        return status >= 100 && status <= 599;
    };
    return Exception;
}(Error));
var exception = new Exception(401, "Invalid API Key");

Compiled JavaScript for TypeScript@2.0.9:

"use strict";
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 Exception = (function (_super) {
    __extends(Exception, _super);
    function Exception(status, reason) {
        if (status === void 0) { status = 500; }
        _super.call(this, reason);
        this.status = status;
        if (!this.isValidStatus(status)) {
            this.status = 500;
        }
    }
    Exception.prototype.isValidStatus = function (status) {
        return status >= 100 && status <= 599;
    };
    return Exception;
}(Error));
var exception = new Exception(401, "Invalid API Key");
@aluanhaddad
Copy link
Contributor

Please see #12123

@brodeuralexis
Copy link
Author

Yep, that better describes it.
Thanks.

@DanielRosenwasser
Copy link
Member

This is an intentional breaking change and documented here.

@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants