mergeSkipNullish
Merge multiple objects from left to right to form a new object.
Fields that are not null
or undefined
in the preceding objects will not be overwritten by null
or undefined
fields from the subsequent objects.
Added in v0.0.4
Usage
ts
import { mergeSkipNullish } from 'parsnip-kit'
const obj1 = { a: 1, b: null, c: undefined }
const obj2 = { b: 2, c: 3, d: null }
const obj3 = { c: undefined, d: 4, e: 5 }
mergeSkipNullish(obj1, obj2, obj3) // { a: 1, b: 2, c: 3, d: 4, e: 5 }
API
Type Parameter
Arg | Type | Description |
---|---|---|
T | extends object | The type of the objects to merge |
Arguments
Arg | Type | Optional | Default | Description |
---|---|---|---|---|
...objs | (T | Nullish)[] | false | undefined | The objects to merge |
Returns
Type |
---|
T |
Type Definition
ts
{
<T extends object, U extends object>(
a: T | Nullish, b: U | Nullish
): SpreadSkipNullish<T, U>
<T extends object, U extends object, V extends object>(
a: T | Nullish, b: U | Nullish, c: V | Nullish
): SpreadSkipNullish<SpreadSkipNullish<T, U>, V>
<T extends object, U extends object, V extends object, W extends object>(
a: T | Nullish, b: U | Nullish, c: V | Nullish, d: W | Nullish
): SpreadSkipNullish<SpreadSkipNullish<SpreadSkipNullish<T, U>, V>, W>
(...objs: any[]): any
}