UNPKG

@monstermann/fn

Version:

A utility library for TypeScript.

25 lines (24 loc) 885 B
import { KeysOfUnion, Simplify } from "type-fest"; //#region src/object/hasProp.d.ts type HasProp<T extends object, U extends KeysOfUnion<T>> = T extends unknown ? U extends keyof T ? Simplify<T & Record<U, Exclude<Required<T>[U], null | undefined>>> : never : never; /** * `hasProp(target, key)` * * Checks if `target` object has the specified `key` property with a non-null and non-undefined value. * * ```ts * hasProp({ a: 1, b: null }, "a"); // true * hasProp({ a: 1, b: null }, "b"); // false * ``` * * ```ts * pipe({ a: 1, b: null }, hasProp("a")); // true * pipe({ a: 1, b: null }, hasProp("b")); // false * ``` */ declare const hasProp: { <T extends object, U extends KeysOfUnion<T>>(key: U): (target: T) => target is HasProp<T, U>; <T extends object, U extends KeysOfUnion<T>>(target: T, key: U): target is HasProp<T, U>; }; //#endregion export { hasProp };