(no title)
eyelidlessness | 1 month ago
Of course it’s different. You have a type that accurately reflects your domain/data model. Doing that helps to ensure you know to implement the necessary runtime checks, correctly. It can also help you avoid implementing a lot of superfluous runtime checks for conditions you don’t expect to handle (and to treat those conditions as invariant violations instead).
tombert|1 month ago
For things that are invariants, that’s also trivial to check against with `if(!isValid(obj)) throw Error`.
dwb|1 month ago
eyelidlessness|1 month ago
The type is a way to communicate (to the compiler, to other devs, to future you) that those are the expected invariants.
The check for invariants is trivial as you say. The value of types is in expressing what those invariants are in the first place.
the-grump|1 month ago