Open hohler opened 5 years ago
@hohler I could replicate this by adding the following test: https://github.com/typestack/class-transformer/commit/b402d62d354f2decd8cdffbf415184cff37c19d5
I'd be happy to work on a PR to fix this once the project is under active maintenance again.
When using plainToClass with a plain object in combination with @Type and a discriminator, it will delete the discriminator from that plain object. A workaround is either to clone the object, or to have
keepDiscriminatorProperty
set to true on the @Type definition. But then it will also be kept in the target object.I think the root cause is in TransformOperationExecutor.ts on line 51:
if (!targetType.options.keepDiscriminatorProperty) delete subValue[targetType.options.discriminator.property];
I can't make a fix / PR right now because of lack of time, but I like to have the issue documented here.