class-transformer: fix: ExposeAll does not work with excludeExtraneousValues
Description
Strategy ‘exposeAll’ does not work as expected with true excludeExtraneousValues flag. Actual behaviour is as all properties were not exposed.
Minimal code-snippet showcasing the problem
class Dog {
name: string;
}
const plainDoggie = {
name: 'Azor',
surname: 'dogs does not have surnames :('
};
const doggie = plainToClass(Dog, plainDoggie, {
strategy: 'exposeAll',
excludeExtraneousValues: true
});
console.log('doggie', doggie);
// should be {name:'Azor'}, but is {} instead
Expected behavior
All properties are exposed. In above example doggie = {name: ‘Azor’}
Actual behavior
Properties are not exposed. In above example doggie = {}
About this issue
- Original URL
- State: open
- Created 3 years ago
- Reactions: 57
- Comments: 28
strategy: 'exposeAll'is a strategy: it should mean that by default, everything is exposed.excludeExtraneousValues: truemeans if something outside the class is in the object, then remove it. The combination of these two options should logically be that you don’t need to decorate anything in the class with@Exposebecause everything will be exposed, but extraneous values should be removed.Thus, this is a bug.
Yes! 👍
you can use
@Exposefor each property that you wanna expose itI faced the same issue so I created an extension method to achieve the wanted behavior:
const myInstance = transformToDto(myDTO, myData);It has been 2 years and this has yet to be resolved… Why?
Any news on this issue?
Any news on this issue? This simple change could be very beneficial for a lot of users.
Sorry for disturbing. @NoNameProvided Could you plz have a look at this issue?
Option
strategy: 'excludeAll'behave allmost the same asexcludeExtraneousValues: true, is that by design?keysare the same exceptisMapandignoreDecorators