@rxap/utilities
Version:
A collection of utility functions, types and interfaces.
17 lines (16 loc) • 947 B
TypeScript
/**
* Removes undefined properties from an object.
* If the 'recursive' argument is set to true, this function will recursively remove undefined properties from nested objects.
*
* @export
* @template T A generic object type
* @param {T} obj The object from which to remove undefined properties
* @param {boolean} [recursive=false] Optional. A boolean indicating whether to recursively remove undefined properties. Defaults to false.
* @returns {Exclude<T, undefined>} A new object of type T, but with all undefined properties removed.
* If the 'recursive' argument is set to true, the returned object will have undefined properties removed from nested objects.
*
* @example
* const obj = { a: 1, b: undefined, c: { d: 4, e: undefined } };
* DeleteUndefinedProperties(obj, true); // returns { a: 1, c: { d: 4 } }
*/
export declare function DeleteUndefinedProperties<T extends {}>(obj: T, recursive?: boolean): Exclude<T, undefined>;