param defaultOptions param options param fields export function extendOptions < T = object > ( defaultOptions , options ? , fields = [ 'relations' ] ) { const subObjects = { } ; if ( ! options ) { options = { } ; } fields . forEach ( field => { if ( Array . isArray ( defaultOptions [ field ] || options [ field ] ) ) { subObjects [ field ] = [ ... ( defaultOptions [ field ] || [ ] ) , ... ( options [ field ] || [ ] ) ] ; } else { subObjects [ field ] = { ... ( defaultOptions [ field ] || { } ) , ... ( options [ field ] || { } ) } ; } } ) ; const result = { ... defaultOptions , ... options , ... subObjects } ; for ( const option of Object . keys ( result ) ) { if ( result [ option ] == null ) { delete result [ option ] ; } } return result ; }