UNPKG

computed-types

Version:

Runtime validation types for TypeScript.

18 lines (17 loc) 933 B
import { FunctionParameters } from './FunctionType'; import { ObjectProperty } from './utils'; export declare type ErrorLike<P extends FunctionParameters = never> = string | ValidationError | ((...args: P) => string | ValidationError); export declare type ObjectPath = ObjectProperty[]; export interface PathError { path: ObjectPath; error: Error; } export declare class ValidationError extends TypeError { errors?: PathError[]; path?: ObjectPath; constructor(message: string, errors?: PathError[]); toJSON?(): Record<string, unknown>; } export declare function toError<P extends FunctionParameters>(error: ErrorLike<P>, ...args: P): ValidationError; export declare function toPathErrors(errorLike: ErrorLike, path: ObjectPath): PathError[]; export declare function createValidationError<P extends FunctionParameters>(errors: PathError[], error: ErrorLike<P> | null | undefined, ...args: P): ValidationError;