spumko/joi — pull request #96 by iamdoron (2013-06-12 18:25:52+00:00)
Title: strings are joy

In joi strings are real joy - they could be just a string, or an object/array in disguise.

I tried to fix a problem where you give a string instead of an object and you expect it to fail. What I saw in the code was an exception that was not handled correctly.

I believe the concept of converting a string/whatever to a type is similar to the '==' operator in javascript, it's a delicate matter, that might throw us to some pits, but it's kinda cool :)

Think about an array; in the previous code a string will be converted to an array. why?
If we want to add that behaviour, we would want something like that:

'a' == ['a']; // true
'a' == 'a'; // also true

Then we should consider not using a type converter, but rather an ambiguous comparison
That is why I added tests which seem redundant now, but if a different mechanism will be used for comparison between types, the tests will still be there, guarding.