3 ms·
Lodash also handles "bad-types" in really graceful ways. In fact, it's almost the primary reason I use it. For example, if you have a nullable array. In plain
by SkyPuncher 4y ago
Lodash also handles "bad-types" in really graceful ways. In fact, it's almost the primary reason I use it.
For example, if you have a nullable array. In plain JS, you have to check the presences of the array, then run `find` (or whatever function). Lodash simply treats it like an empty array - returning nothing.
This is particularly handy in React where it creates clutter to have to check for the empty state.
- shortcake27 4y agoIn your nullable array example, you could just use optional chaining. There’s no need for lodash. I personally feel this type of ultra-defensive programming where all types are assumed bad only harms you long run, adding complexity where it isn’t necessary to solve problems that don’t exist, and swallowing errors making it harder to debug. Exceptions exist for a reason. When I switched to TS it was a great incentive to ditch lodash because it was munging all my types. This in turn simplified my code as it made me aware of unnecessary guards, coercions, and errors that lodash was swallowing.