cloneObjectWith()function
cloneObjectWith(input: T, key: K, value: T[K]): T
cloneObjectWith(input: T, key: K, value: V): T & { [KK in K]: V }| Param | Type | |
|---|---|---|
input | T | The object to clone. required |
key | K | The key of the prop to change. required |
value | T[K] | The value of the prop to change. required |
input | T | required |
key | K | required |
value | V | required |
| Return | |
|---|---|
T | A new object with the changed prop, or the original object if the value was unchanged. |
T & { [KK in K]: V } |
Shallow clone an object with a single changed value.
- If the value is unchanged the original object is returned unchanged.
Examples
cloneObjectWith({ a: 1 }, "a", 2); // { a: 2 }