UNPKG

@monstermann/fn

Version:

A utility library for TypeScript.

26 lines (25 loc) 1.16 kB
import { Simplify } from "type-fest"; //#region src/object/testAll.d.ts type TestAllPredicates<T extends object> = Partial<{ [K in keyof T]: (value: NoInfer<T>[K], key: K, target: Readonly<T>) => boolean }>; type TestAllResult<T extends object, U> = Simplify<T & { [K in Extract<keyof U, keyof T>]: U[K] extends ((value: any, key: any, target: any) => value is infer V) ? V : T[K] }>; /** * `testAll(target, props)` * * Checks if all properties in `target` object pass their corresponding predicate functions in `props` object. * * ```ts * testAll({ a: 5, b: 2 }, { a: (x) => x > 3, b: (x) => x > 0 }); // true * testAll({ a: 1, b: 2 }, { a: (x) => x > 3, b: (x) => x > 0 }); // false * ``` * * ```ts * pipe({ a: 5, b: 2 }, testAll({ a: (x) => x > 3, b: (x) => x > 0 })); // true * pipe({ a: 1, b: 2 }, testAll({ a: (x) => x > 3, b: (x) => x > 0 })); // false * ``` */ declare const testAll: { <T extends object, U extends TestAllPredicates<T>>(props: U): (target: T) => target is TestAllResult<T, U>; <T extends object, U extends TestAllPredicates<T>>(target: T, props: U): target is TestAllResult<T, U>; }; //#endregion export { testAll };