class-transformer icon indicating copy to clipboard operation
class-transformer copied to clipboard

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

Open onhate opened this issue 1 year ago • 0 comments

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 avatar Jul 06 '24 01:07 onhate