diff --git a/src/TransformOperationExecutor.ts b/src/TransformOperationExecutor.ts index fe1da8e32..98a294cd5 100644 --- a/src/TransformOperationExecutor.ts +++ b/src/TransformOperationExecutor.ts @@ -341,13 +341,17 @@ export class TransformOperationExecutor { } } - if (finalValue !== undefined || this.options.exposeUnsetFields) { + if (finalValue !== undefined) { if (newValue instanceof Map) { newValue.set(newValueKey, finalValue); } else { newValue[newValueKey] = finalValue; } } + + if (finalValue === undefined && !this.options.exposeUnsetFields) { + delete newValue[newValueKey]; + } } else if (this.transformationType === TransformationType.CLASS_TO_CLASS) { let finalValue = subValue; finalValue = this.applyCustomTransformations( @@ -357,13 +361,17 @@ export class TransformOperationExecutor { value, this.transformationType ); - if (finalValue !== undefined || this.options.exposeUnsetFields) { + if (finalValue !== undefined) { if (newValue instanceof Map) { newValue.set(newValueKey, finalValue); } else { newValue[newValueKey] = finalValue; } } + + if (finalValue === undefined && !this.options.exposeUnsetFields) { + delete newValue[newValueKey]; + } } }