Skip to main content

Function: hasAtLeastOneKeyInObject()

hasAtLeastOneKeyInObject<T, K>(obj: T, keys: readonly K[]): obj is T & { [key in PropertyKey]-?: unknown }

Checks whether any of the keys are in the obj

Type parameters

Type parameter
T extends object
K extends PropertyKey

Parameters

ParameterTypeDescription
objTThe object to check
keysreadonly K[]The keys to find in the object

Returns

obj is T & { [key in PropertyKey]-?: unknown }

true if at least one of the keys is in the obj, false otherwise.

Example

const obj = { a: 1, b: 2, c: 3 };
console.log(hasAtLeastOneKeyInObject(obj, ['a'])); // true
console.log(hasAtLeastOneKeyInObject(obj, ['d'])); // false

Source

lib/hasAtLeastOneKeyInObject.ts:17