Function getSafe

  • Avoid "can't access property of undefined" errors in a more readable way.

    Type Parameters

    • T

    Parameters

    • fn: (() => T)

      Function that wraps a nested property access

        • (): T
        • Returns T

    • Optional defaultVal: T

      Optional - the value to return if property access failed

    Returns T | undefined