3 ms·
I do appreciate your expounding on this, but I assure you I do get it. Using types to track these things is the appropriate solution. In most languages you wou
by knome 3y ago
I do appreciate your expounding on this, but I assure you I do get it.
Using types to track these things is the appropriate solution. In most languages you would either create a wrapping object you can get the original back from or perhaps extend the basic type. Here we can just use `as` to cast the value into an intersection with the number, which I assume allows it to continue being used as a number but will catch failures on functions that needs a ValidatedInputString, in much the same way the an inherited subtype might. Probably better.
I get it and you are right, this is the right thing to do.
My original comment was that for those that do not do this appropriate type level work to track that we have validated a value, then it becomes an assumed aspect of the branch.
This was very, very common in older code I've seen. I think I can safely assume that it still happens today, though if I am wrong I'll be glad that parsing the values into new types has made enough headway that it is seen as simply the default.
Because it is certainly the RightThingToDo.
- riwsky 3y agoOh, yeah, it happens all the time even in TS code. We’re on the same page.