-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
TypeScript 2.1.x fails to extend Error #12790
Comments
I got hit by the same problem. |
This is an intended change. |
This is documented here and very interesting, relevant discussions can be found in #12123 #12581 among others. |
@aluanhaddad thanks for the info. Would be cool to link this here as well: http://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-1.html section |
@dbaeumer great point. That would definitely be good. |
I had this issue and I followed the recommendation in the linked related issues to remove extends Error. Seems to work. |
Ace, good to have the link because I missed too :) @andriijas I've just made a small npm module to allow you to extend it adds a little easier and also so you don't have to set the prototype for errors that extend errors etc. (so handles the chaining for you) :) |
@jamesrichford +1 for initiative with the new package. -10 million for forking the web! 😆 |
@aluanhaddad haha how do you mean breaking the web? |
I meant to write "forking the web" but my brain isn't working at all today... |
@jamesrichford I would recommend using any of the existing packages on NPM today instead of making a new one. For instance, I use https://www.npmjs.com/package/make-error, but there's a few others. One note on your code, I would do https://github.com/jamesrichford/extendo-error/blob/master/src/extendo-error.ts#L17 outside the constructor and not inside since it's really the same operation every time. |
@blakeembrey absolutely agree usually would but this package didn't come up on my searches thanks for pointing it out - will be useful for the future. Also thanks for the mini code review :) |
All good, finding quality modules on NPM can be tricky :) Especially for this, took me a while and various code reviews to decide I'd use and build with it going forward. |
TypeScript Version: 2.1.4
Code
Given the following definition
I get the following output for 2.0.3
However for version 2.1.1 and 2.1.4 I get the following
Expected behavior:
The extended error to behave as in the first example
Actual behavior:
It seems as if the error has not been extended at all
Thanks very much for your assistance in advance.
James
The text was updated successfully, but these errors were encountered: