Function safeAccess

    • Provides a way to safely access an object's data / entries using either a dotted accessor string or an array of exact property keys.

      Array indexes may only be accessed by number through the array accessor form.

      Type Parameters

      • T extends object

        Type of data.

      • const P extends SafeAccessor

        Accessor type.

      • R = DeepAccess<T, P>

        Return value / Inferred deep access type or any provided default value type.

      Parameters

      • data: T

        An object to access entry data.

      • accessor: P

        A dotted string accessor or an array of exact string, number, or symbol property keys.

      • OptionaldefaultValue: DeepAccess<T, P> extends undefined ? R : DeepAccess<T, P>

        (Optional) A default value to return if an entry for accessor is not found.

      Returns DeepAccess<T, P> extends undefined ? R : DeepAccess<T, P>

      The value referenced by the accessor.