The type of the input object, must extend UnknownRecord
The type of the key to check for, must extend PropertyKey (string | number | symbol)
true
if the object has the specified key as its own property,
false
otherwise. When true
, TypeScript narrows the object type to
guarantee the key exists.
Type guard function that checks if an object has a specific key as its own property.
This function uses
Object.hasOwn()
to check if the given object has the specified key as its own property (not inherited). It acts as a type guard that narrows the type of the object to guarantee the key exists, enabling type-safe property access.Type Narrowing Behavior:
true
, TypeScript narrows the object type to include the checked key