# Custom Errors in TypeScript 2.1

DevFeed: [Custom Errors in TypeScript 2.1](<https://devfeed.tech/articles/custom-errors-in-typescript-2-1-31839.md>)

Original publisher: [Read original article](<https://www.metachris.dev/2017/01/custom-errors-in-typescript-2.1/>)

Author: Chris Hager

Published: 2017-01-06T00:00:00Z

Content type: tutorial

Language: en

Sources: [Chris Hager](<https://devfeed.tech/sources/chris-hager.md>)

Topics: [TypeScript](<https://devfeed.tech/topics/typescript.md>)

Tags: [class](<https://devfeed.tech/tags/class.md>), [constructor](<https://devfeed.tech/tags/constructor.md>), [custom](<https://devfeed.tech/tags/custom.md>), [errors](<https://devfeed.tech/tags/errors.md>), [native](<https://devfeed.tech/tags/native.md>), [prototype](<https://devfeed.tech/tags/prototype.md>), [subclass](<https://devfeed.tech/tags/subclass.md>), [typescript](<https://devfeed.tech/tags/typescript.md>)

## AI overview

A tutorial on handling custom Error subclasses in TypeScript 2.1, where extending built-in types such as Error may leave subclass methods undefined and cause instanceof checks to fail. It presents a solution that reliably works, including with native and Bluebird promises.

## Source excerpt

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.