From 25fbcb782c843b2aec0b526d2958b435dd46870f Mon Sep 17 00:00:00 2001 From: rybak Date: Wed, 3 Apr 2024 20:26:27 +0300 Subject: [PATCH] fix: exposeUnsetFields when useDefineForClassFields is set --- src/TransformOperationExecutor.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/TransformOperationExecutor.ts b/src/TransformOperationExecutor.ts index 0533f03df..49abcd4fb 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]; + } } }