true
if the check passes, false
otherwise.
hasKeys({ a: 1, b: 2, c: 3 }, ['a', 'b']) // true
hasKeys({ foo: 1, bar: 2 }, ['buzz']) // false
const obj: { a: string; b: string } | { c: number; d: number }
if (hasKeys(obj, ['a'])) {
obj // type: { a: string; b: string; }
obj.c // error
} else {
obj // type: { c: number; d: number; }
obj.a // error
}
import { assert } from 'uft'
const obj: { a: string; b: string } | { c: number; d: number }
assert(hasKeys(obj, ['d']), 'expected object to have key "d"')
obj // type: { c: number; d: number }
Generated using TypeDoc
Checks if an object has all of the provided own properties.