Function hasProp

  • Checks if a property exists in an object using a dot-notation path

    Type Parameters

    • T extends NestedObject
    • P extends string

    Parameters

    • obj: T

      The object to check

    • path: P

      The dot-notation path to the property (e.g., 'user.name')

    Returns boolean

    true if the property exists, false otherwise

    Throws

    Error if input validation fails

    Example

    const obj = { user: { name: 'Flavio Ever' } };
    hasProp(obj, 'user.name'); // Returns true
    hasProp(obj, 'user.age'); // Returns false
    hasProp(obj, 'user.skills.0'); // Works with arrays