hasDictionary<V, T, K>(value, key): value is T & object & View<K, Dictionary<V>>
Tests whether a value of type T contains a property key whose type tests positively when tested with
isDictionary. 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 object.
// type of obj -> unknown if (hasNumber(obj, 'status')) { // type of obj -> { status: number } if (hasDictionary(obj, 'data')) { // type of obj -> { status: number } & { data: Dictionary } } elseif (hasString('error')) { // type of obj -> { status: number } & { error: string } } }
Tests whether a value of type
T
contains a propertykey
whose type tests positively when tested with isDictionary. 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 typeobject
.