type UnsafeMergeKey = '__proto__' | 'constructor' | 'prototype'; type SafeMergeProps = Omit; type SafeProp = K extends keyof SafeMergeProps ? SafeMergeProps[K] : never; type DeepSafeMergeValue = T extends readonly unknown[] ? { [K in keyof T]: DeepSafeMergeValue; } : T extends Record ? DeepSafeMergeProps : T; type DeepSafeMergeProps = { [K in keyof SafeMergeProps]: DeepSafeMergeValue>; }; /** Properties that exist in both `T1` and `T2`, typed as `T2`'s version. */ export type CommonProps = { [k in keyof SafeMergeProps & keyof SafeMergeProps]: SafeProp extends never ? never : SafeProp extends never ? never : SafeProp; }; /** Properties present in `T1` but not in `T2`. */ export type PropsInFirstOnly = Omit, keyof SafeMergeProps>; /** Recursively merges two object types. Matching keys are merged; unique keys are kept. */ export type MergeTwo = PropsInFirstOnly & PropsInFirstOnly & { [k in keyof CommonProps]: SafeProp extends Record ? SafeProp extends Record ? MergeTwo, SafeProp> : DeepSafeMergeValue> : DeepSafeMergeValue>; }; /** Recursively merges a tuple of object types from left to right. */ export type Merge = T['length'] extends 3 ? MergeTwo> : T['length'] extends 2 ? MergeTwo : T['length'] extends 1 ? DeepSafeMergeProps : T extends [...infer K, infer PL, infer L] ? Merge<[Merge<[...K]>, MergeTwo]> : never; /** * Deep-merges multiple objects into one. Later values override earlier ones; * nested objects are merged recursively rather than replaced. * Prototype-polluting keys (`__proto__`, `constructor`, and `prototype`) are * ignored. * * @example * ```ts * const a = { x: 1, nested: { a: true } }; * const b = { y: 2, nested: { b: false } }; * const result = deepExtend(a, b); * // { x: 1, y: 2, nested: { a: true, b: false } } * ``` * * @param args - Two or more non-null objects to merge. * @returns A new object containing the deep-merged result. * @throws If no arguments are provided or any argument is not a non-null object. */ export declare const deepExtend: (...args: T) => Merge; export {};