UNPKG

narrow-minded

Version:

Easy typeof validations with sophisticated TypeScript inference.

59 lines 1.03 kB
import { Narrower } from './schema'; /** * */ export type DiffResult = { level: number; property: string; expected: Narrower; received: unknown; }; /** * * @example * // Given this failed narrow: * narrow( * { * title: 'string', * count: 'number', * }, * { * title: 10, * count: 'bad boy', * }, * ) * //=> false * * // The diff would be: * diffNarrow( * { * title: 'string', * count: 'number', * }, * { * title: 10, * count: 'bad boy', * }, * ) * //=> * [ * { * level: 1, * property: 'title', * expected: 'string', * received: 10, * }, * { * level: 1, * property: 'count', * expected: 'number', * received: 'bad boy', * }, * ] * @param n * @param u * @returns Array of `DiffResult` objects that indicate where `u` failed to satisfy `n`. An empty * array is the same as `narrow(n, u)` returning true. */ export declare const diffNarrow: <N extends Narrower>(n: N, u: unknown) => DiffResult[]; //# sourceMappingURL=diff.d.ts.map