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

Provide a first-class support for checking truthiness of booleans #904

Closed
tomdohnal opened this issue May 21, 2020 · 2 comments · Fixed by #910
Closed

Provide a first-class support for checking truthiness of booleans #904

tomdohnal opened this issue May 21, 2020 · 2 comments · Fixed by #910

Comments

@tomdohnal
Copy link
Contributor

tomdohnal commented May 21, 2020

Hi :)

I've been enjoying using yup to validate both forms and API requests, so I'd like to say a huge thank you in the first place! :)

Anyways, what I'm missing is a more canonical way of checking if a boolean is true that doing something like:

yup.boolean().oneOf([true]),

Although the above-mentioned snippet does the job perfectly, it feels to me like a workaround for missing functionality. And I believe it's quite common to require a boolean to be true (checking checkboxes with agreements, ...).

I know that changing how .required() works for booleans (to only accept true) values is not possible (backwards compatibility, ...).

What I'd suggest is to either create a general truthy() checker on the mixed() type which would check if the value passed is truthy as JavaScript evaluates it (e. g. everything except for null, undefined, 0, false and some other).

Or create an explicit isTrue() checked on the boolean() type which would simply check if the value is true.

If you'd be interested in adding this functionality to the API, I'd be happy to send a PR with whatever solution you'd prefer :)

@jquense
Copy link
Owner

jquense commented May 21, 2020

I'd be ok with a isTrue and isFalse methods on boolean

@tomdohnal
Copy link
Contributor Author

OK, thank you. I'll do my best to send a PR within a week :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants