Remove undefined input checks from all functions #48
Replies: 2 comments
-
Absolutely. |
Beta Was this translation helpful? Give feedback.
-
Obviously, we need to avoid implicit conversions in functions. (My English is not very good, so all of the above is from translation software) |
Beta Was this translation helpful? Give feedback.
-
Currently, the TypeScript definitions don't reflect the current behavior of Radashi functions. In many of the functions, when an input is null or undefined, the function tries to avoid a thrown error, returning whatever makes most sense.
There are 3 possible directions from here.
My argument for taking approach 2 is straight-forward: TypeScript does the job of checking for garbage input already. If you're using a REST API or other untyped data source, you should be using Zod or a similar library to perform runtime type validation. The current behavior of Radashi is actively harmful, because it can make it harder to surmise the actual root of an unexpected behavior. “Why is this object empty when I'm expecting it not to be? [Minutes or hours later...] Oh! It's because Radashi is coercing an unexpectedly undefined value into an empty object!”
Alright, that should be enough to begin this discussion. This is open to all opinions. As this is a breaking change, it will be a while before a decision is made.
Beta Was this translation helpful? Give feedback.
All reactions