import { Cast, Head, Push, Resolve, Shift } from '../../../types'; import { slice } from '../../arrayLike'; import { forOwn } from '../forOwn/forOwn'; /** * Assigns U to T. * * @typeParam T - An object to assign to. * @typeParam U - An object to assign. * * @return An assigned object type. */ export type Assign = Omit & U; /** * Recursively assigns U[] to T. * * @typeParam T - An object to assign to. * @typeParam U - A tuple contains objects. * * @return An assigned object type. */ export type Assigned = { 0: T, 1: Assigned>, Shift, N, Push>, }[ C['length'] extends N ? 0 : 1 ] extends infer A ? Cast : never; export function assign( object: T ): T; export function assign( object: T, ...sources: U ): Resolve> /** * Assigns all own enumerable properties of all source objects to the provided object. * * @param object - An object to assign properties to. * * @return An object assigned properties of the sources to. */ export function assign( object: T ): any { // eslint-disable-next-line prefer-rest-params, prefer-spread slice( arguments, 1 ).forEach( source => { forOwn( source, ( value, key ) => { object[ key ] = source[ key ]; } ); } ); return object; }