import has from 'lodash/has' ; import set from 'lodash/set' ; import get from 'lodash/get' ; example export function definePropertyAtPath < AttributesType extends PropertyDescriptor > ( target , propertyPath , attributes ) { const propertyName = propertyPath [ propertyPath . length - 1 ] ; const parentPath = propertyPath . slice ( 0 , - 1 ) ; if ( parentPath . length && ! has ( target , parentPath ) ) { set ( target , parentPath , { } ) ; } const parent = parentPath . length ? get ( target , parentPath ) : target ; Object . defineProperty ( parent , propertyName , attributes ) ; }