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

Signature TypeScript complète, extraite du fichier util.

typescript

API

Paramètres

Paramètres d'entrée acceptés par cet util.

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

API

Valeur de retour

La valeur retournée par cet util.

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

Usage

Exemples

Extraits de code prêts à coller.

Guard on multiple keys

typescript