Thanks for the great article! One thing that came to mind is that in the great Pragmatic Programmer book the authors say your code should always fail early. So if something unexpected happens, one shouldn't just accept it but raise an exception. So could your example of using allow be interpreted as following their "use asserts in production" advice, what do you think?
For run-time type checking in TS, have you taken a look at the io-ts library? It's nice when the user or server inputs are complex.
Cool! I also can't resist linking the great Parse, don't validate blog post by Alexis King, though it's most directly concerned with strongly typed languages like Haskell.
Thanks for the great article! One thing that came to mind is that in the great Pragmatic Programmer book the authors say your code should always fail early. So if something unexpected happens, one shouldn't just accept it but raise an exception. So could your example of using
allow
be interpreted as following their "use asserts in production" advice, what do you think?For run-time type checking in TS, have you taken a look at the io-ts library? It's nice when the user or server inputs are complex.
First - yes! "Using asserts in production" is absolutely another way of describing what I'm trying to get across!
And second, no - I haven't checked out
io-ts
. But I appreciate the heads-up, and I'll definitely give it a look!Cool! I also can't resist linking the great Parse, don't validate blog post by Alexis King, though it's most directly concerned with strongly typed languages like Haskell.
I referenced the exact same blog post in my response!
You might be interested in seeing my attempt at applying those ideas to TypeScript:
dev.to/cipharius/comment/15im8