-
Notifications
You must be signed in to change notification settings - Fork 504
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: How to correctly use plainToInstance with Set<T>? #1446
Comments
Solved using this class Person {
@Transform(value => new Set(value.value))
public numbers: Set<number> = new Set()
} But note that readme specifies this should work, which it doesn't Lines 736 to 737 in 05b0151
What is the problem here? |
I just ran into this issue as well. I actually checked out the master codebase and ran this test, which passed. it('Creates a Set', () => {
class TestSet {
@Type(() => Set)
test: Set<string>;
constructor(data?: any) {
Object.assign(this, plainToInstance(this.constructor as any, data))
}
}
const record = new TestSet({
test: ['a']
})
console.log(record.test.add('b'))
}) I then did the exact same thing in my project using the same version (0.5.1), but received an error about Regardless, @sorashi, your fix worked for me, thank you! |
Hello, could you provide some details on your environment please? The best would be if you could create a demo environment (repo, or stackblitz or something like that), which would help to reproduce the error. Thanks. |
@diffy0712 Here you go https://github.com/sorashi/class-transformer-1446-repro I observed this a year ago, so I tried replicating my environment back then. It's Vite+React+TypeScript app. The bug can be observed in the browser console. Instructions are in the readme in the repo. The code that uses |
Thank you, I will take a look! |
I was trying to use a
Set
, which should be supported according to readme. Minimal example:The problem:
Actual output:
Expected output:
How do I use it correctly?
The text was updated successfully, but these errors were encountered: