ow
ow copied to clipboard
`Ow` instances are mutable
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.
I'm totally open to making it immutable.