-
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
[bug/proposal] for boolean prop type and enabled enableImplicitConversion
flag
#306
Comments
Looks like we have the same issue. |
This issue also means |
Since this is still open, is there any work around? |
@adzamkomladev I'm still waiting for an answer from the developer on how it should work |
same problem here |
Until the issue gets fixed, I'm using this approach to handle it: // ...
@IsBoolean()
@Transform(it => {
switch (it) {
case 'true':
return true;
case 'false':
return false;
default:
return it;
}
})
verified!: boolean;
// ... |
Same problem here... I have a DTO with a boolean type on it, but I can't actually treat it like a boolean because at runtime it has type string everywhere... |
The shortest version I can think of import { Transform } from "class-transformer";
export function ToBoolean() {
return Transform(v => ["1", 1, "true", true].includes(v));
} |
@numToStr I think this is rather misguided as it will convert all objects not in the set ["1", 1, "true", true] to false. I think this is far too broad a definition for type coercion. |
I have same problem :( any solution? |
A tracking issue has been created for this at #550. If you have any feedback regarding the feature, please leave it there. |
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. |
version:
"class-transformer": "0.2.3"
example:
returned:
TestClass { prop: true }
expected:
TestClass { prop: false }
proposal:
if
value === 'true' || value === true || value === 1 || value === '1'
thentrue
otherwise
false
somethink like ths:
The text was updated successfully, but these errors were encountered: