sindresorhus / is

Type check values
MIT License
1.68k stars 109 forks source link

Fix assertion message for `.all` and `.any` #132

Closed scraggo closed 3 years ago

scraggo commented 3 years ago

This PR fixes #131

Approach: Add an options object to assertType. This allows a custom failure message from the calling code. It's a function that returns a string and passed in as getValuesMessage to the options object.

What do you think of the approach?

sindresorhus commented 3 years ago

Does the issue also apply to .all? If so, we should fix it there too.

scraggo commented 3 years ago

@sindresorhus I tried a slightly different approach in my latest push and applied it to .all as well.

I decided to keep the options object for this approach because it's now a boolean flag. {multipleValues: true} is more readable in my opinion than a bare boolean. This isn't a strong opinion and it's easily changed if you disagree 😄 (I could also make a new function to handle multiple values, named assertTypes or assertMultipleTypes)

sindresorhus commented 3 years ago

Thanks :)