Skip to content

question: Correctly use plainToInstance & instanceToPlain in class instance include a Set. #1820

Open
@shuklaRishabh46

Description

@shuklaRishabh46

Description

This is my implementation:
type Val = "A" | "B" | "C"
class MyClass {
mySet: Set = new Set()
}

here when I put
@type(() => Set) or @type(() => Set)) above line mySet: Set = new Set()

instanceToPlain is not giving set, instead converting into empty array (set is empty)

Proposed solution

Found this solution from this questions raised on this sub.

putting this works:
@expose()
@Transform(({ value }) => new Set(value)))

Do i have to use transform? and Why?

Sorry if it a repeated question.

Metadata

Metadata

Assignees

No one assigned

    Labels

    flag: needs discussionIssues which needs discussion before implementation.type: featureIssues related to new features.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions