Skip to content

compactObject

Functions

compactObject()

compactObject<T>(object): { [K in string | number | symbol as IfNullish<T[K], never, K>]: T[K] }

移除对象值为 nullundefined 的属性

Type parameters

Parameter
T extends Object

Parameters

ParameterTypeDescription
objectT目标对象

Returns

{ [K in string | number | symbol as IfNullish<T[K], never, K>]: T[K] }

Example

ts
compactObject({ a: 0, b: undefined, c: null, d: '', f: false, e: NaN })
// => { a: 0, d: '', f: false, e: NaN }