Skip to content

Instantly share code, notes, and snippets.

@datatypevoid
Created May 16, 2018 15:44
Show Gist options
  • Save datatypevoid/d52ba0a616df9fefa278b18cc2ebd55c to your computer and use it in GitHub Desktop.
Save datatypevoid/d52ba0a616df9fefa278b18cc2ebd55c to your computer and use it in GitHub Desktop.
Generic TypeScript Error class
/*
* Imports
*/
/*
* Structures
*/
abstract class BaseError<T> extends Error {
protected readonly _type: T;
public get type (): T {
return this._type;
}
protected constructor (type: T, message: string) {
super(message);
this._type = type;
(Object as any).setPrototypeOf(this, BaseError.prototype);
}
}
/*
* Exports
*/
export {
BaseError
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment