Open JeffreyArt1 opened 1 year ago
@JeffreyArt1 I have the same issue, my workaround is
const plain = {
name: {
first: 'John',
last: 'Doe',
},
};
@Exclude()
class Person {
@Expose()
@Transform(({ obj }) => obj.name.first)
firstName: string;
@Expose()
@Transform(({ obj }) => obj.name.last)
lastName: string;
}
Description
I have noticed that when using the @Expose decorator with the same name for multiple properties in the same class, the transform function is only evaluated for the first property.
For example, consider the following code:
Here's a snippet
Expected behavior
Actual behavior
When
plainToClass
is called with this class and a plain object, only the transform function for thefirstName
property is evaluated, while thelastName
property remains undefined.I believe this is a bug in the class-transformer library, as both properties should be transformed based on their respective transform functions. Correct me if i'm wrong.