class-transformer
class-transformer copied to clipboard
feat: casting empty numberstring to null
Description
In the MVC web service, when receiving user input as object from the controller through form submit, each fields should be casted from string to suitable type. and class-transformer returns 0 when converting empty string to number.
so, IsNotEmpty of class-validator doesn't work for number field because the number field user not input will be initialized to 0.
If class-transformer returns null when converting empty characters to numbers, then IsNotEmpty can be used for number fields as well.
Checklist
- [x] the pull request title describes what this PR does (not a vague title like
Update index.md) - [x] the pull request targets the default branch of the repository (
develop) - [x] the code follows the established code style of the repository
npm run prettier:checkpassesnpm run lint:checkpasses
- [x] tests are added for the changes I made (if any source code was modified)
- [ ] documentation added or updated
- [x] I have run the project locally and verified that there are no errors
I do not think this should be added. This could cause other issues for existing users of this library. I do believe that this problem should be handled via a custom Transformer in your application code. Edit: In js Number('') will return 0, which is expected.