sindresorhus / ow

Function argument validation for humans
https://sindresorhus.com/ow/
MIT License
3.8k stars 105 forks source link

Issue with ArrayPredicates and .any checka #217

Open vladfrangu opened 3 years ago

vladfrangu commented 3 years ago

Hello, it's me again 👋

I've encountered an interesting issue with Predicates and .any checks.

Consider the following predicate:

const choicesPredicate = ow.array.ofType<[string, string | number]>(
    ow.array.exactShape([stringPredicate, ow.any(ow.string, integerPredicate)]),
);

This currently throws the following error, while running the code works and asserts it correctly:

image

Now, I don't know if this is not an intended use case for this, so bare with me, but if it is, then this seems like a small mistake somewhere. Looking at what the typings expect, ofType takes in BasePredicate, while exactShape takes Predicate. Any reason for that, is that an oversight?

Thanks!

sindresorhus commented 3 years ago

Probably just an oversight. See: https://github.com/sindresorhus/ow/commit/b3c5fbde0edea4d8172cf0640e4050b5bd58aefa