Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/dtils/safe_unknown.ts>SafeUnknownObject#sureGet

The best unofficial library of utilities for Deno applications
Go to Latest
method SafeUnknownObject.prototype.sureGet
import { SafeUnknownObject } from "https://deno.land/x/dtils@2.3.1/safe_unknown.ts";

Gets the value of an object path in the object. If a key doesn't exist, an error is thrown. Unlike get, null is not immediately returned.

Examples:

new SafeUnknownObject({ foo: null }).sureGet('foo', 'bar', 'bin', 'baz') // Error: Expected data to be an object, but found type null at $.foo
new SafeUnknownObject({}).sureGet('foo') // Error: Expected to find a value for key "foo" at $
new SafeUnknownObject({}).sureGet('foo', 'bar', 'bin', 'baz').isNull() // Error: Expected to find a value for key "foo" at $
new SafeUnknownObject({ foo: "hello" }).sureGet('foo', 'bar', 'bin', 'baz') // Error: Expected data to be an object, but found type string at $.foo
new SafeUnknownObject({ foo: { bar: { bin: { baz: "Hello" }}}}).sureGet('foo', 'bar', 'bin', 'baz').asString() // "Hello"

Parameters

...keys: string[]