index.d.ts 932 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /**
  2. * Create a new error constructor instance.
  3. */
  4. declare function makeError(name: string): makeError.Constructor<makeError.BaseError>;
  5. /**
  6. * Set the constructor prototype to `BaseError`.
  7. */
  8. declare function makeError<T extends Error>(super_: { new (...args: any[]): T }): makeError.Constructor<T & makeError.BaseError>;
  9. /**
  10. * Create a specialized error instance.
  11. */
  12. declare function makeError<T extends Error, K>(name: string | Function, super_: K): K & makeError.SpecializedConstructor<T>;
  13. declare module makeError {
  14. /**
  15. * Use with ES2015+ inheritance.
  16. */
  17. export class BaseError implements Error {
  18. message: string;
  19. name: string;
  20. stack: string;
  21. constructor(message?: string);
  22. }
  23. export interface Constructor <T> {
  24. new (message?: string): T;
  25. super_: any
  26. prototype: T
  27. }
  28. export interface SpecializedConstructor <T> {
  29. super_: any
  30. prototype: T
  31. }
  32. }
  33. export = makeError;