Skip to content

test

ts
function Object.test<
    T extends object,
    U extends keyof AllUnionFields<T>,
>(
    target: T,
    key: U,
    predicate: (value: AllUnionFields<T>[U]) => boolean,
): target is Test<T, U, AllUnionFields<T>[U]>

Checks if the key property of target object passes the predicate function test.

Example

ts
import { Object } from "@monstermann/object";

Object.test({ a: 5, b: 2 }, "a", (x) => x > 3); // true
Object.test({ a: 1, b: 2 }, "a", (x) => x > 3); // false
ts
import { Object } from "@monstermann/object";

pipe(
    { a: 5, b: 2 },
    Object.test("a", (x) => x > 3),
); // true

pipe(
    { a: 1, b: 2 },
    Object.test("a", (x) => x > 3),
); // false