Function objPropertyValueToGetter

  • Converts the specified properties of an object into getter functions.

    Type Parameters

    • V

      The type of the values of the object.

    • T extends Record<ObjectKey, V>

      The type of the object.

    Parameters

    • object: T

      The object whose properties are to be converted into getter functions.

    • Rest ...propertyNames: ObjectKey[]

      The names of the properties to be converted into getter functions.

    Returns T

    The object with the specified properties converted into getter functions.

    Throws

    Throws an error if the property descriptor for a specified property name is not found.

    Example

    const obj = { a: 1, b: 2, c: 3 };
    objPropertyValueToGetter(obj, 'a', 'b');
    obj.a;;
    //=> 1
    obj.b;;
    //=> 2
    obj.c;;
    //=> 3

Generated using TypeDoc