npm.io
1.0.3 • Published 2 years ago

@types/makeerror

Licence
MIT
Version
1.0.3
Deps
0
Size
6 kB
Vulns
0
Weekly
0
Stars
51.4K

Installation

npm install --save @types/makeerror

Summary

This package contains type definitions for makeerror (https://github.com/daaku/nodejs-makeerror#readme).

Details

Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/makeerror.

index.d.ts

export = makeError;

declare function makeError<T extends makeError.DefaultData>(
    name: string,
    defaultMessage?: string,
    defaultData?: T,
): makeError.CustomErrorConstructor<T>;

declare namespace makeError {
    type DefaultData = Record<string, unknown> & { proto?: CustomError<Record<string, unknown>> };

    interface CustomErrorConstructor<T extends Record<string, unknown>> {
        new<U, V>(
            message?: U extends Record<string, unknown> ? U : string,
            data?: V extends Record<string, unknown> ? V : never,
        ): U extends Record<string, unknown> ? V extends Record<string, unknown> ? CustomError<V>
            : CustomError<U>
            : V extends Record<string, unknown> ? CustomError<V>
            : CustomError<T>;

        <U, V>(
            message?: U extends Record<string, unknown> ? U : string,
            data?: V extends Record<string, unknown> ? V : never,
        ): U extends Record<string, unknown> ? V extends Record<string, unknown> ? CustomError<V>
            : CustomError<U>
            : V extends Record<string, unknown> ? CustomError<V>
            : CustomError<T>;

        readonly prototype: "proto" extends keyof T ? T["proto"] : BaseError;
    }

    interface CustomError<T extends Record<string, unknown>> extends BaseError {
        data: DataObject<T>;
        fileName?: string;
        lineNumber?: number;
    }
}

type DataObject<T extends Record<string, unknown>> = {
    [P in keyof T as Exclude<P, "proto">]: T[P];
};

interface BaseError extends Error {
    toString(): string;
}

Additional Details

  • Last updated: Tue, 07 Nov 2023 0939 GMT
  • Dependencies: none

Credits

These definitions were written by yutak23.