-
Notifications
You must be signed in to change notification settings - Fork 512
feat: allow casting strings to boolean #626
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
Comments
@QuanticPotatoes - will this fix be committed into next official version? |
"false" is true ... In my opinion, this should not be casted, correct type or transform annotation should be used.
|
Good Job! I was looking for it! Is there any way to return an error if no "true" or "false" was sent? Other way could be use with class-validator:
but just does not work for me and I don't have any idea about what is happening I would throw a 400 BAD REQUEST exception error if no "true" or "false" was sent. |
Your statement is "false" |
After transforming value is boolean, not boolean-string. That's why u get error. Either make @isboolean() or remove @Transform() |
I just want undefined not to be tranformed to false actually |
Hey, guys.
It's fishy, but it works. |
I think a good argument for why 'false' should be treated as false is that class transformer gets used for parsing using requests and if the request is a GET and not a post all values get converted into strings thus false becomes 'false'. I'm having this trouble when using nestjs and doing GET requests. I use the |
For me worked DTO:
Controller:
|
Duplicate of #550. |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Hi, I use class-transformer on NestJS and a cast problem occured during the conversion of the request payload.
Example :
We got :
The defining class is :
https://github.com/nestjs/nest/blob/master/packages/common/pipes/validation.pipe.ts#L96
When the
plainToClass
function was executed such as :After a little digging, i found the caused into the function
transform
:https://github.com/typestack/class-transformer/blob/develop/src/TransformOperationExecutor.ts#L108
So i made a patch locally to solve the issue :
Is it an attended behavior from the function to not convert a string "true"/"false" to a Boolean ?
Current version: 0.4.0
Best regards
The text was updated successfully, but these errors were encountered: