Skip to content

question: How to correctly use plainToInstance with Set<T>? #1446

Open
@sorashi

Description

@sorashi

I was trying to use a Set, which should be supported according to readme. Minimal example:

class Person {
    @Type(() => Number)
    public numbers: Set<number> = new Set()
}

const person = new Person()
person.numbers = new Set([1,2,3,4,5])
const plain = instanceToPlain(person)
const instance = plainToInstance(Person, plain)

console.log(person)
console.log(plain)
console.log(instance)

The problem:
Actual output:

Person { numbers: Set { 1, 2, 3, 4, 5 } }
{ numbers: [ 1, 2, 3, 4, 5 ] }
Person { numbers: [ 1, 2, 3, 4, 5 ] }

Expected output:

Person { numbers: Set { 1, 2, 3, 4, 5 } }
{ numbers: [ 1, 2, 3, 4, 5 ] }
Person { numbers: Set { 1, 2, 3, 4, 5 } }

How do I use it correctly?

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