Options
All
  • Public
  • Public/Protected
  • All
Menu

Module object/propSetBy

Index

References

Functions

References

Renames and re-exports propSetBy

Functions

  • Makes a shallow clone of an object, setting or overriding the specified property with the result of fn call.

    Note: If property in the object is equal to value by reference then function just returns object without changes

    example
     propSetBy('a', x => x+1, {a: 1}); //=> {a: 2}
    

    Type parameters

    • K: string | number | symbol

    • O: Record<any, any>

    • R

    Parameters

    • prop: K

      The property name to set

    • fn: ObjBase<K, O[K], R>

      The function to execute

    • obj: O

      The object to clone

    Returns ReplaceType<O, K, R>

    A new object equivalent to the original except for the changed property.

  • Makes a shallow clone of an object, setting or overriding the specified property with the result of fn call.

    Note: If property in the object is equal to value by reference then function just returns object without changes

    example
     propSetBy('a', x => x+1, {a: 1}); //=> {a: 2}
    

    Type parameters

    • K: string | number | symbol

    • V

    • R

    Parameters

    • prop: K

      The property name to set

    • fn: ObjBase<K, V, R>

      The function to execute

    Returns <O>(obj: O) => ReplaceType<O, K, R>

    A new object equivalent to the original except for the changed property.

  • Makes a shallow clone of an object, setting or overriding the specified property with the result of fn call.

    Note: If property in the object is equal to value by reference then function just returns object without changes

    example
     propSetBy('a', x => x+1, {a: 1}); //=> {a: 2}
    

    Type parameters

    • K: string | number | symbol

    Parameters

    • prop: K

      The property name to set

    Returns { <O, R>(fn: ObjBase<K, O[K], R>, obj: O): ReplaceType<O, K, R>; <V, R>(fn: ObjBase<K, V, R>): <O>(obj: O) => ReplaceType<O, K, R> }

    A new object equivalent to the original except for the changed property.

Generated using TypeDoc