cloneObjectWith()function

cloneObjectWith(input: T, key: K, value: T[K]): T
cloneObjectWith(input: T, key: K, value: V): T & { [KK in K]: V }
ParamType
inputT
The object to clone. required
keyK
The key of the prop to change. required
valueT[K]
The value of the prop to change. required
inputT
required
keyK
required
valueV
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 }