Function safeAccess

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

    Array indexes may only be accessed by number through the array property-key form.

    Type Parameters

    • T extends object

      Type of data.

    • const P extends PropertyPath

      Property path 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.

    • path: P

      A dotted string property path 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 property path is not found.

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

    The value referenced by the path.