@@ -170,9 +170,17 @@ export class TransformOperationExecutor {
170
170
if ( metadata . options && metadata . options . discriminator && metadata . options . discriminator . property && metadata . options . discriminator . subTypes ) {
171
171
if ( ! ( value [ valueKey ] instanceof Array ) ) {
172
172
if ( this . transformationType === TransformationType . PLAIN_TO_CLASS ) {
173
- type = metadata . options . discriminator . subTypes . find ( ( subType ) => subType . name === subValue [ metadata . options . discriminator . property ] ) ;
173
+ type = metadata . options . discriminator . subTypes . find ( ( subType ) => {
174
+ if ( subValue && metadata . options . discriminator . property in subValue ) {
175
+ return subType . name === subValue [ metadata . options . discriminator . property ]
176
+ }
177
+ } ) ;
174
178
type === undefined ? type = newType : type = type . value ;
175
- if ( ! metadata . options . keepDiscriminatorProperty ) delete subValue [ metadata . options . discriminator . property ] ;
179
+ if ( ! metadata . options . keepDiscriminatorProperty ) {
180
+ if ( subValue && metadata . options . discriminator . property in subValue ) {
181
+ delete subValue [ metadata . options . discriminator . property ] ;
182
+ }
183
+ }
176
184
}
177
185
if ( this . transformationType === TransformationType . CLASS_TO_CLASS ) {
178
186
type = subValue . constructor ;
@@ -217,7 +225,7 @@ export class TransformOperationExecutor {
217
225
if ( newValue . constructor . prototype ) {
218
226
const descriptor = Object . getOwnPropertyDescriptor ( newValue . constructor . prototype , newValueKey ) ;
219
227
if ( ( this . transformationType === TransformationType . PLAIN_TO_CLASS || this . transformationType === TransformationType . CLASS_TO_CLASS )
220
- && ( ( descriptor && ! descriptor . set ) || newValue [ newValueKey ] instanceof Function ) ) // || TransformationType === TransformationType.CLASS_TO_CLASS
228
+ && ( ( descriptor && ! descriptor . writable ) || newValue [ newValueKey ] instanceof Function ) ) // || TransformationType === TransformationType.CLASS_TO_CLASS
221
229
continue ;
222
230
}
223
231
0 commit comments