Function: hasAtLeastOneKeyInObject()
hasAtLeastOneKeyInObject<
T
,K
>(obj
:T
,keys
: readonlyK
[]):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
Parameter | Type | Description |
---|---|---|
obj | T | The object to check |
keys | readonly 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