UNPKG

promi-safe

Version:

Type-safe promise wrapper with runtime validation support

18 lines (15 loc) 746 B
import { StandardSchemaV1 } from '@standard-schema/spec'; interface Options { onFail?: (issues: readonly StandardSchemaV1.Issue[]) => void; throwOnError?: boolean; } type SafePromise<T> = Promise<T> & { safe: (schema: StandardSchemaV1, options?: Options) => Promise<T>; }; declare class ValidationError extends Error { readonly issues: readonly StandardSchemaV1.Issue[]; constructor(issues: readonly StandardSchemaV1.Issue[], message?: string); } declare const validateResponse: <T>(promise: Promise<T>) => (schema: StandardSchemaV1, options?: Options) => Promise<T>; declare const makeSafePromise: <T>(promise: Promise<T>) => SafePromise<T>; export { type SafePromise, ValidationError, makeSafePromise, validateResponse };