import { inspect } from 'util' import rethrow from './rethrow.js' import type { Assert, Keyed } from './prelude.js' /** @returns assert for `Keyed`, which is check-forced record `Record`. */ const keyed = (a: Assert): Assert> => value => { if (value === null || typeof value !== 'object' || Array.isArray(value)) { throw new TypeError(`Expected object, got ${inspect(value)}.`) } const value_ = value as Record for (const key in value_) { rethrow(a, `[${inspect(key)}]`)(value_[key]) } return value_ as Keyed } export default keyed