has

Commons
stable

Type-safe own-property check. Returns true (and narrows the type) when every key in the provided array is an own property of the object. Relies on Object.prototype.hasOwnProperty to avoid false positives from prototype properties.

API

Signature

Full TypeScript signature sourced from the util file.

typescript

API

Parameters

Input parameters accepted by this util.

obj
required
object
The object to inspect.
key
required
Array<T>
One or more property key strings. All must be own properties for the guard to pass.

API

Return value

The value returned by this util.

A type predicate that narrows obj to Record<T, unknown> when every key is present as an own property.

Usage

Examples

Ready-to-paste usage snippets.

Guard on multiple keys

typescript