hasBoolean<T, K>(value, key): value is T & object & View<K, boolean>
Tests whether a value of type T contains a property key of type boolean. If so, the type of the tested value is
narrowed to reflect the existence of that key for convenient access in the same scope. Returns false if the
property key does not exist on the object or the value stored by that key is not of type boolean.
// type of obj -> unknown if (hasBoolean(obj, 'enabled')) { // type of obj -> { enabled: boolean } if (hasBoolean(obj, 'hidden')) { // type of obj -> { enabled: boolean } & { hidden: boolean } } }
Tests whether a value of type
T
contains a propertykey
of typeboolean
. If so, the type of the tested value is narrowed to reflect the existence of that key for convenient access in the same scope. Returnsfalse
if the property key does not exist on the object or the value stored by that key is not of typeboolean
.