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

fix: allow plain to class to convert from Set to Set instead of from Set to Array #1723

Open
onhate opened this issue Jul 6, 2024 · 0 comments · May be fixed by #1724
Open

fix: allow plain to class to convert from Set to Set instead of from Set to Array #1723

onhate opened this issue Jul 6, 2024 · 0 comments · May be fixed by #1724
Labels
status: needs triage Issues which needs to be reproduced to be verified report. type: fix Issues describing a broken feature.

Comments

@onhate
Copy link

onhate commented Jul 6, 2024

Description

When converting from plain to class on an plain object that already has a Set the target property that is also a Set is converted to Array.

class User {
  id: number;
  name: string;
  @Type(() => Set)
  weapons: Set<string>;
}

const plainUser = {
  id: 1,
  name: 'Max Pain',
  weapons: new Set(['knife', 'eagle', 'ak-47']),
};

const classedUser = plainToInstance(User, plainUser);
expect(classedUser.weapons).toBeInstanceOf(Set); <~~~ fails here

Expected behavior

If the target is of type Set and source already is a Set should return a Set.

Actual behavior

It converts the target property of the class to Array.

@onhate onhate added status: needs triage Issues which needs to be reproduced to be verified report. type: fix Issues describing a broken feature. labels Jul 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: needs triage Issues which needs to be reproduced to be verified report. type: fix Issues describing a broken feature.
1 participant