getUntypedProperty
Attempt to get a property from the wrapped object with some arbitrary string key. If no property is found on the given object at the given key, null
is returned.
import { obj } from "@tsly/obj";
type Gizmo = { type: "polygon"; sides: number } | { type: "point" };
function getGizmo(): Gizmo {
return Math.random() < 0.5
? { type: "point" }
: { type: "polygon", sides: 3 };
}
const sides = obj(getGizmo()).getUntypedProperty("sides");
console.log(sides ?? "no sides");