Skip to main content

Function: hasProperty()

hasProperty<K>(value: unknown, property: K): value is Record<K, unknown>

Defined in: shared/utils/typeGuards.ts:82

Checks if a value exposes a specific own property.

Type Parametersโ€‹

Kโ€‹

K extends PropertyKey

Property key that must exist on the value.

Parametersโ€‹

valueโ€‹

unknown

Value to evaluate as an object.

propertyโ€‹

K

Property name that must be present on the value.

Returnsโ€‹

value is Record<K, unknown>

true when the property exists directly on the value.

Exampleโ€‹

if (hasProperty(obj, "foo")) {
// obj has the 'foo' property
}