Skip to content

question: Exclude properties not included in the specified group when using plainToClass #1787

Open
@chiuinggum

Description

@chiuinggum

I was trying to...

export class Test {
  @Expose({ groups: ['1'] })
  prop1: string;

  @Expose({ groups: ['2'] })
  prop2: string;
}

const test = {
  prop1: 'prop1',
  prop2: 'prop2'.
}

const inst = plainToClass(Test, test, {
  groups: ['1'],
  excludeExtraneousValue: true,
})

console.log(inst)
// { prop1: 'prop1', prop2: undefined }

The problem:
I wonder if there's a way to exclude properties not included in the specified group when using plainToClass, not just make it undefined. In this case, I want the inst to be only { prop1: 'prop1' } instead of { prop1: 'prop1', prop2: undefined }

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: questionQuestions about the usage of the library.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions