unchangeable • Docs
unchangeable / setProperty
Returns a new object with object[key]
set to value
if object[key]
is strictly different from value
. Otherwise, returns the provided object
.
If key
is undefined
, returns the object
untouched.
If value
is undefined
, ensures that the returned object does not contain the key
.
If object
is undefined
, it is considered as an EMPTY_OBJECT
.
const result = setProperty({ a: 1 }, "b", 2)
// { a: 1, b: 2 }
The object to update.
The key of the object to update.
The value to set the object key to.
setProperty<
T
,K
>(object
,key
,value
?):Omit
<T
,K
>
Returns a new object with object[key]
set to value
if object[key]
is strictly different from value
. Otherwise, returns the provided object
.
If key
is undefined
, returns the object
untouched.
If value
is undefined
, ensures that the returned object does not contain the key
.
If object
is undefined
, it is considered as an EMPTY_OBJECT
.
• T extends object
• K extends string
| number
| symbol
= keyof T
• object: undefined
| T
• key: K
• value?: typeof REMOVE
Omit
<T
, K
>
const result = setProperty({ a: 1 }, "b", 2)
// { a: 1, b: 2 }
The object to update.
The key of the object to update.
The value to set the object key to.
setProperty<
T
,K
>(object
,key
,value
):T
Returns a new object with object[key]
set to value
if object[key]
is strictly different from value
. Otherwise, returns the provided object
.
If key
is undefined
, returns the object
untouched.
If value
is undefined
, ensures that the returned object does not contain the key
.
If object
is undefined
, it is considered as an EMPTY_OBJECT
.
• T extends object
• K extends string
| number
| symbol
= keyof T
• object: undefined
| T
• key: K
• value: T
[K
]
T
const result = setProperty({ a: 1 }, "b", 2)
// { a: 1, b: 2 }
The object to update.
The key of the object to update.
The value to set the object key to.
setProperty<
T
,K
,V
>(object
,key
,value
):T
&{ readonly [key in K]: V }
Returns a new object with object[key]
set to value
if object[key]
is strictly different from value
. Otherwise, returns the provided object
.
If key
is undefined
, returns the object
untouched.
If value
is undefined
, ensures that the returned object does not contain the key
.
If object
is undefined
, it is considered as an EMPTY_OBJECT
.
• T extends object
• K extends string
| number
| symbol
• V
• object: undefined
| T
• key: K
• value: V
T
& { readonly [key in K]: V }
const result = setProperty({ a: 1 }, "b", 2)
// { a: 1, b: 2 }
The object to update.
The key of the object to update.
The value to set the object key to.