Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/samualtnorman/lib. A collection of common utilities I need. www.npmjs.com/package/@samual/lib
Something went wrong. Try again.
1234567891011121314151617181920import { isRecord } from "./isRecord"
export function getDeepObjectProperty(object: Record<string | symbol, unknown>, keys: (string | symbol)[]): unknown { const lastKey = keys.pop()
if (!lastKey) return object
for (const key of keys) { const child = object[key]
if (!isRecord(child)) throw Error(`Expected object, got ${typeof child}`)
object = child }
return object[lastKey]}