Skip to content

hasProp

ts
function Object.hasProp<
    T extends object,
    U extends KeysOfUnion<T>,
>(target: T, key: U): target is HasProp<T, U>

Checks if target object has the specified key property with a non-null and non-undefined value.

Example

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

Object.hasProp({ a: 1, b: null }, "a"); // true
Object.hasProp({ a: 1, b: null }, "b"); // false
ts
import { Object } from "@monstermann/object";

pipe({ a: 1, b: null }, Object.hasProp("a")); // true
pipe({ a: 1, b: null }, Object.hasProp("b")); // false