Skip to content

fix: @Transform() is not called for undefined values if exposeDefaultValues=true #1330

Open
@keyCat

Description

@keyCat

Description

@Transform() is not being called for properties with undefined values if exposeDefaultValues set to true.
While this may be intentional behaviour, I do not think that this is correct, since not every property of a class can define a default value.

Minimal code-snippet showcasing the problem

export class Example {
  propertyA: string;
  
  @Transform(({ value }) => {
    console.log('propertyB is:', value);
    return value; 
   })
  propertyB?: string;
}

plainToInstance(Example, {  propertyA: 'value' });
// > propertyB is: undefined

plainToInstance(Example, {  propertyA: 'value' }, { exposeDefaultValues: true });
// no console.log

Expected behavior

In my opinion, transformation must be called always in this case.

Actual behavior

See Description

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: needs triageIssues which needs to be reproduced to be verified report.type: fixIssues describing a broken feature.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions