custom-error.d.ts 1.1 KB

12345678910111213141516171819202122
  1. interface ErrorOptions {
  2. cause?: unknown;
  3. }
  4. export declare class CustomError extends Error {
  5. name: string;
  6. constructor(message?: string, options?: ErrorOptions);
  7. }
  8. export {};
  9. export interface CustomErrorInterface extends Error {
  10. }
  11. export interface CustomErrorProperties {
  12. [property: string]: any;
  13. }
  14. export interface CustomErrorConstructor<Properties extends CustomErrorProperties> extends ErrorConstructor {
  15. readonly prototype: CustomErrorInterface;
  16. new (...args: any[]): CustomErrorInterface & Properties;
  17. (...args: any[]): CustomErrorInterface & Properties;
  18. }
  19. export declare type GenericErrorConstructor = ErrorConstructor | EvalErrorConstructor | RangeErrorConstructor | ReferenceErrorConstructor | SyntaxErrorConstructor | TypeErrorConstructor | URIErrorConstructor | CustomErrorConstructor<CustomErrorProperties>;
  20. declare type CustomErrorFunction<Properties> = (this: Properties, ...args: any[]) => void;
  21. export declare function customErrorFactory<Properties extends CustomErrorProperties>(fn: CustomErrorFunction<Properties>, parent?: GenericErrorConstructor): CustomErrorConstructor<Properties>;
  22. export {};