metachris / metachris.com-comments

Comments for metachris.com
https://www.metachris.com
0 stars 0 forks source link

Custom Errors in TypeScript 2.1 #6

Open utterances-bot opened 3 years ago

utterances-bot commented 3 years ago

Custom Errors in TypeScript 2.1 · Chris Hager

TypeScript 2.1 introduced a number of breaking changes, among them that “Extending built-ins like Error, Array, and Map may no longer work”. For a subclass like the following: class FooError extends Error { constructor(m: string) { super(m); } sayHello() { return "hello " + this.message; } } methods may be undefined on objects returned by constructing these subclasses, so calling sayHello will result in an error. instanceof will be broken between instances of the subclass and their instances, so (new FooError()) instanceof FooError will return false.

https://www.metachris.com/2017/01/custom-errors-in-typescript-2.1/