blob: 9fa60415189e0b4a7b0b071762ebce22fdfb675a [file] [log] [blame]
Samuel Shuert274a4d62023-12-01 15:04:55 -05001/**
2 * Create a new error constructor instance.
3 */
4declare function makeError(
5 name: string
6): makeError.Constructor<makeError.BaseError>;
7
8/**
9 * Set the constructor prototype to `BaseError`.
10 */
11declare function makeError<T extends Error>(super_: {
12 new (...args: any[]): T;
13}): makeError.Constructor<T & makeError.BaseError>;
14
15/**
16 * Create a specialized error instance.
17 */
18declare function makeError<T extends Error, K>(
19 name: string | Function,
20 super_: K
21): K & makeError.SpecializedConstructor<T>;
22
23declare namespace makeError {
24 /**
25 * Use with ES2015+ inheritance.
26 */
27 export class BaseError extends Error {
28 message: string;
29 name: string;
30 stack: string;
31
32 constructor(message?: string);
33 }
34
35 export interface Constructor<T> {
36 new (message?: string): T;
37 super_: any;
38 prototype: T;
39 }
40
41 export interface SpecializedConstructor<T> {
42 super_: any;
43 prototype: T;
44 }
45}
46
47export = makeError;