Skip to content
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

feat: support automatic casting of the string representation of a boolean value #1328

Closed
mubin-ct opened this issue Sep 4, 2022 · 3 comments · May be fixed by #1329
Closed

feat: support automatic casting of the string representation of a boolean value #1328

mubin-ct opened this issue Sep 4, 2022 · 3 comments · May be fixed by #1329
Labels
status: duplicate Issue is being tracked already in another issue. type: feature Issues related to new features.

Comments

@mubin-ct
Copy link

mubin-ct commented Sep 4, 2022

Description

If we try to convert a value that has typeof string, then in some cases it returns the wrong value. e.g value: 'true' will return true, while on the other hand value: 'false' will also return the true.

Minimal code-snippet showcasing the problem
Consideration: A network access request.

import { Expose, plainToInstance } from 'class-transformer';

class RoleDTO {
  @Expose()
    id: number
  @Expose()
  canAccess: boolean
}
plainToInstance(RoleDTO, { id: 1, canAccess: 'true' }, { enableImplicitConversion: true })
plainToInstance(RoleDTO, { id: 2, canAccess: 'false' }, { enableImplicitConversion: true })

Expected behavior

RoleDTO with the id:1 should have canAccess: true and RoleDTO with the id:2 should have canAccess: false

Actual behavior

RoleDTO with id 1, and 2 have canAccess: true

This is a common JS Boolean conversion issue, I will be submitting a PR for this.

@mubin-ct mubin-ct added status: needs triage Issues which needs to be reproduced to be verified report. type: fix Issues describing a broken feature. labels Sep 4, 2022
@andylizf
Copy link

any update?

@NoNameProvided NoNameProvided added type: feature Issues related to new features. status: duplicate Issue is being tracked already in another issue. and removed type: fix Issues describing a broken feature. status: needs triage Issues which needs to be reproduced to be verified report. labels May 4, 2024
@NoNameProvided
Copy link
Member

Duplicate of #550.

@NoNameProvided NoNameProvided closed this as not planned Won't fix, can't repro, duplicate, stale May 4, 2024
@NoNameProvided NoNameProvided changed the title fix: if type specified to boolean, and provide a string, returns the wrong boolean value feat: support automatic casting of the string representation of a boolean value May 4, 2024
Copy link

github-actions bot commented Jun 4, 2024

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 4, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status: duplicate Issue is being tracked already in another issue. type: feature Issues related to new features.
3 participants