-
Notifications
You must be signed in to change notification settings - Fork 507
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
Cannot transform string to number #1672
Comments
same question |
It seems that there is some problem with the environment and not the If you log the I have tested your code:
I am not sure why it behaves differently in these cases yet. |
Same error here |
To note a few things:
I think there are a few serious limitations to this feature unfortunately, which should be mentioned somewhere. But in the example provided by @stad-nico I see |
This issue appeared recently in my code, without any changes in my parts. __decorate([
(0, class_validator_1.IsNumber)(),
__metadata("design:type", Number)
], User.prototype, "AGE", void 0); But when i use this code: const validatedUser = plainToClass(User, userJson, {
enableImplicitConversion: true,
}); the AGE property stays as String instead of being transformed to Number. For the time being I'll add |
Could you checkout a commit from before when it supposadely worked and check if there has been any package-lock.json (or yarn, or pnpm whatever you use) updated? thank you:) |
Same with Vite and code: import 'reflect-metadata';
import { plainToClass } from 'class-transformer';
class Entry {
num: number;
}
console.log(plainToClass(Entry, { num: '5.00' })); |
Description
Trying to convert number strings wont cast the type to number. This was supposed to be fixed in
0.2.2
(Issue #179)Minimal code-snippet showcasing the problem
Expected behavior
Actual behavior
The workaround using
@Type(() => Number)
still works, however I expect number strings to be converted without additionally specifying the type.Using
The text was updated successfully, but these errors were encountered: