Skip to content
Functionutilsv0.8.17

keepDefined

Copies only the keys holding a value, dropping both undefined and null.

keepDefined<TObject, TKey>(
    source: TObject,
    keys: readonly TKey[]
): Partial<
    Pick<
        TObject,
        TKey extends never ? keyof TObject : TKey
    >
>

TObject

the original object type you're pulling from

TObject

the original object type you're pulling from

TKey

the keys to copy when defined

TKey

the keys to copy when defined

source

source: TObject

the object to read values from

keys

keys: readonly TKey[]

optional list of keys to include when present.

Default:all keys