import { Config } from './types' ; param baseConfig param configExtension export function mergeConfigs ( baseConfig , configExtension ) { for ( const key in configExtension ) { mergePropertyRecursively ( baseConfig as any , key , configExtension [ key as keyof Config ] ) ; } return baseConfig ; } const hasOwnProperty = Object . prototype . hasOwnProperty ; const overrideTypes = new Set ( [ 'string' , 'number' , 'boolean' ] ) ; function mergePropertyRecursively ( baseObject , mergeKey , mergeValue ) { if ( ! hasOwnProperty . call ( baseObject , mergeKey ) || overrideTypes . has ( typeof mergeValue ) || mergeValue === null ) { baseObject [ mergeKey ] = mergeValue ; return ; } if ( Array . isArray ( mergeValue ) && Array . isArray ( baseObject [ mergeKey ] ) ) { baseObject [ mergeKey ] = ( baseObject [ mergeKey ] as unknown [ ] ) . concat ( mergeValue ) ; return ; } if ( typeof mergeValue === 'object' && typeof baseObject [ mergeKey ] === 'object' ) { if ( baseObject [ mergeKey ] === null ) { baseObject [ mergeKey ] = mergeValue ; return ; } for ( const nextKey in mergeValue ) { mergePropertyRecursively ( baseObject [ mergeKey ] as Record < string , unknown > , nextKey , mergeValue [ nextKey as keyof object ] ) ; } } }