3 ms·
> With JS, I almost never want to verify only that a value is of a specific type; I want to look at its contents We're pretty deep down in abstract discussions
by hnarn 6y ago
> With JS, I almost never want to verify only that a value is of a specific type; I want to look at its contents
We're pretty deep down in abstract discussions here and I have no idea what your code looks like or what it does, but I think it's helpful to point out that knowing the type means you already know the contents to some extent.
The way I see it, checking if a value is what you expect is always good, but if you additionally get an error automatically because your number is now suddenly an e-mail address, or the function you wrote that expects phone numbers suddenly gets a name instead, in my mind that's "built in testing". It doesn't make other testing unnecessary but it sure raises the bar for cleanliness -- which is especially useful when you're working with other components that aren't JS where types do really matter (like databases, for example).
- ZenPsycho 6y agoI want to know what kind of code you're writing where a number can suddenly become an email address. I certainly hope you're not using type checking as a substitute for input sanitization.