Skip to content

Unexpected z.coerce.boolean() result with "false" #1672

Closed

Description

@WORMSS

Yes, yes, it makes sense that what you are doing under the hood is Boolean("whatever") and that means Boolean("false") equates to true...

But I believe this is a silly enough gotcha that it is worth to note in the docs..
Or even if there was a z.coerce.boolean({ treatStringFalseAsFalse: true })

I just don't want people to get confused..

Number(String(123)) === 123 // makes sense
Boolean(String(false)) !== false // will be a head scratcher at first glance

Activity

  1. colinhacks commented on Dec 12, 2022

    @colinhacks
    Owner

    Good call, just added some docs to this effect. This decision is discussed in slightly more detail at #1630

  2. JacobWeisenburger commented on Dec 25, 2022

    @JacobWeisenburger
    Contributor

    Has this been addressed?

    If so, can I close this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions