Skip to content

Extending from Error doesn't work correctly under tsc 1.6.2 #5069

Closed
@dbaeumer

Description

@dbaeumer

Test case:

myError.ts

class MyError extends Error {
    constructor(message: string) {
        super(message);
    }
}

let error = new MyError('Error Message');
console.log(error.message);

tsconfig.json

{
    "compilerOptions": {
        "target": "ES5",
        "module": "commonjs"
    }
}

compile and run using node:

node myError.js

Observe: nothing is printed to the console. Debugging it shows that the message passed to super is not recorded. Something seems very strange with the prototype chain in this case.

I was under the impression from #3516 that this should work now even if generating ES5 code. If not possible for ES5 then the compiler should produce an error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    QuestionAn issue which isn't directly actionable in code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions