const TYPE_OBJECT = '[object Object]' ; internal export default function merge < T1 , T2 > ( target , source ) { const result = target ; if ( ! source ) { return result ; } const bKeys = Object . keys ( source ) as ( keyof T2 ) [ ] ; if ( bKeys . length === 0 ) { return result ; } for ( const key of bKeys ) { const value = source [ key ] ; if ( Object . prototype . toString . call ( value ) === TYPE_OBJECT && Object . getPrototypeOf ( value ) === Object . prototype ) { if ( result [ key ] == null ) { result [ key ] = { } ; } result [ key ] = merge ( result [ key ] , value ) ; } else if ( Array . isArray ( value ) ) { if ( result [ key ] == null ) { result [ key ] = [ ] ; } result [ key ] = result [ key ] . concat ( value ) ; } else { result [ key ] = value ; } } return result ; }