Skip to content
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

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

Closed
dbaeumer opened this issue Oct 2, 2015 · 1 comment
Closed

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

dbaeumer opened this issue Oct 2, 2015 · 1 comment
Labels
Question An issue which isn't directly actionable in code

Comments

@dbaeumer
Copy link
Member

dbaeumer commented Oct 2, 2015

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.

@mhegazy
Copy link
Contributor

mhegazy commented Oct 2, 2015

The issue is with how these built in types are hand eked by the engine. They are extensible as per the es6 spec, but do not think the engines are there yet.

Here is some related discussion #1168 (comment)

@mhegazy mhegazy added the Question An issue which isn't directly actionable in code label Oct 21, 2015
@mhegazy mhegazy closed this as completed Oct 21, 2015
@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
Question An issue which isn't directly actionable in code
Projects
None yet
Development

No branches or pull requests

2 participants