Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
chiuinggum opened this issue Nov 20, 2024 · 0 comments
Labels
type: question Questions about the usage of the library.

Comments

@chiuinggum
Copy link

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 }

@chiuinggum chiuinggum added the type: question Questions about the usage of the library. label Nov 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: question Questions about the usage of the library.
Development

No branches or pull requests

1 participant