Samuel Shuert | 274a4d6 | 2023-12-01 15:04:55 -0500 | [diff] [blame^] | 1 | /** |
| 2 | * Create a new error constructor instance. |
| 3 | */ |
| 4 | declare function makeError( |
| 5 | name: string |
| 6 | ): makeError.Constructor<makeError.BaseError>; |
| 7 | |
| 8 | /** |
| 9 | * Set the constructor prototype to `BaseError`. |
| 10 | */ |
| 11 | declare 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 | */ |
| 18 | declare function makeError<T extends Error, K>( |
| 19 | name: string | Function, |
| 20 | super_: K |
| 21 | ): K & makeError.SpecializedConstructor<T>; |
| 22 | |
| 23 | declare 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 | |
| 47 | export = makeError; |