Common errors.
npm install --save @blackglory/errors
# or
yarn add @blackglory/errorstype CustomErrorConstructor<T extends CustomError = CustomError> =
new (message?: string) => T
interface SerializableError {
name: string
message: string
stack: string | null
ancestors: string[]
}class CustomError extends Error {}CustomError has better default behaviors than Error:
console.errorprints the correct exception name, notError.instanceofoperator matches based on names rather than inheritance relationships, which helpsSerializableError instanceof CustomError.
class AssertionError extends CustomError {}function isError(val: unknown): val is Error
function isntError<T>(val: T): val is Exclude<T, Error>function normalize(err: Error): SerializableErrorfunction hydrate(err: SerializableError): Errorfunction isSerializableError(val: unknown): val is SerializableError/**
* @throws {AssertionError}
*/
function assert(condition: unknown, message?: string): asserts conditionfunction getErrorNames(err: Error | SerializableError): Iterable<string>function traverseErrorPrototypeChain(err: Error): Iterable<Error>