withProp()function

withProp(input: T, key: K, value: T[K]): T
ParamType
inputT
The object to set the prop on. required
keyK
The key of the prop to set. required
valueT[K]
The value of the prop to set. required
Return
T
A new object including the set prop, or the original object if the value was unchanged.

Set a prop on an object (immutably) and return a new object including that prop.

  • If the value is unchanged the original object is returned unchanged.

Examples

withProp({ a: 1 }, "b", 2); // { a: 1, b: 2 }