In my recent coding endeavor, I've crafted the following function:
function extend(obj, key, value) {
return { ...obj, [key]: value }
}
Ideally, I want to utilize this function in a versatile manner, with obj
representing an Object
of which the type will be identified at the callsite, key
as a constant string at the callsite, and value
standing for a value whose type is known during the call. The existing obj
may or may not contain the specified key
, and the former value linked to that key could differ from the new value
.
Exploring the Utility Types reference, no suitable option seems available to define a relevant type for extend
. Is there a viable solution to address this challenge?