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

Ow instances are mutable #195

Open
mmkal opened this issue Dec 10, 2020 · 1 comment
Open

Ow instances are mutable #195

mmkal opened this issue Dec 10, 2020 · 1 comment

Comments

@mmkal
Copy link
Contributor

mmkal commented Dec 10, 2020

This can lead to some pretty strange behaviour:

const ow = require('ow')

const array = ow.array

ow([1], array) // ok
ow([''], array.ofType(ow.string)) // ok
ow([1], array) // ArgumentError: (array) Expected `item` to be of type `string` but received type `number`

Many users won't hit this because ow.array and all the other props return a new value every time they're accessed. This should probably be documented at a minimum, but I wondered if there'd be any interest in a refactor to make the Predicates and their validators immutable, and replace addValidator with withValidator or similar which would return a new instance.

@sindresorhus
Copy link
Owner

I'm totally open to making it immutable.

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

No branches or pull requests

2 participants