/** * Convert any kind of value to an error instance. Unless the value is already * an error instance, it's stringified and used as the error message. */ export declare function toError(value: unknown): Error; /** * Returns error.code property if the error object has it, otherwise returns undefined. */ export declare function getErrorCode(error: Error & { code?: string; }): string | undefined; /** * Creates an error with error code. Helpful when `instanceof` can't be used * because the error was serialized and then deserialized. * @example * ```ts * try { * throw new ErrorWithCode('message', { code: 'ENOENT' }); * } catch (error) { * if (getErrorCode(toError(error)) === 'ENOENT') { * // ... * } * } * ``` */ export declare class ErrorWithCode extends Error { code?: string; constructor(message?: string, options?: { code?: string; cause?: unknown; }); } /** * Allows the type checker to detect non-exhaustive switch statements. * @example * ```ts * declare const align: 'left' | 'right' | 'middle'; * switch (align) { * case 'left': return 1; * case 'right': return 2; * // type error since 'middle' is not handled * default: throw new UnreachableCaseError(align); * } * ``` */ export declare class UnreachableCaseError extends Error { constructor(switchValue: never); } export declare function stringifyErrorStack(error: unknown): string; export declare function errorToPlainObject(error: T): T & { message: string; name: string; stack: string | undefined; }; /** * Checks if the `error` is an object compatible with the Error interface; that is, * it has properties 'name' and 'message' of type string. The object could be an * instance of an Error, or it could be some other kind of object that has these * properties. */ export declare function isErrorLikeObject(error: unknown): error is Error; //# sourceMappingURL=errors.d.ts.map