withProp()function
withProp(input: T, key: K, value: T[K]): T
| Param | Type | |
|---|---|---|
input | T | The object to set the prop on. required |
key | K | The key of the prop to set. required |
value | T[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 }