Skip to content

Utils / objectHasOwn

Function: objectHasOwn()

objectHasOwn<ObjectType, Key>(object: ObjectType, key: Key): object is ObjectType & Record<Key, unknown>

A strongly-typed version of Object.hasOwn(). Returns a boolean indicating whether the given object has the given property as its own property.

Type Parameters

Type Parameter
ObjectType
Key extends PropertyKey

Parameters

ParameterType
objectObjectType
keyKey

Returns

object is ObjectType & Record<Key, unknown>

Example

ts
import {objectHasOwn} from '@hacxy/utils';
objectHasOwn({}, 'hello'); //=> false
objectHasOwn([1, 2, 3], 0); //=> true

MIT Licensed