import { ObjectLiteralExpression , PropertyAssignment , StructureKind } from 'ts-morph' ; export function updateObjectProperty ( args ) { const { expression , name , value } = args ; let propertyAssignment = expression . getProperty ( name ) as PropertyAssignment | undefined ; if ( value === undefined ) { if ( propertyAssignment ) { propertyAssignment . remove ( ) ; } return ; } if ( ! propertyAssignment ) { propertyAssignment = expression . addProperty ( { name , kind : StructureKind . PropertyAssignment , initializer : 'undefined' , } ) as PropertyAssignment ; } propertyAssignment . setInitializer ( JSON . stringify ( value ) ) ; }