←back to thread

Parse, Don't Validate (2019)

(lexi-lambda.github.io)
389 points melse | 2 comments | | HN request time: 0.415s | source
Show context
mirekrusin ◴[] No.27640199[source]
In typescript parsing/asserting types with combinators works very well merging runtime with static type system [0], it has to be used at i/o boundary, then it enters static type system guarantee and no assertions are necessary, makes very nice codebase.

[0] https://github.com/appliedblockchain/assert-combinators

replies(1): >>27640428 #
lloydatkinson ◴[] No.27640428[source]
I wish it had actual proper examples. I've no idea how to use that.
replies(3): >>27640723 #>>27642258 #>>27642707 #
1. hermanradtke ◴[] No.27642258[source]
Check out https://github.com/gcanti/io-ts/blob/master/index.md instead. I find it more composable and you can define a codec and get a native type from it so you are only defining things once.
replies(1): >>27642689 #
2. mirekrusin ◴[] No.27642689[source]
Assert combinators are composable, light, terse (very little verbosity), types can be defined in single place, instead of type/interface definition you can use return type of assert function.

They don’t go into deep category theory, you won’t find monads and friends, they are first level, straightforward any typescript developer can pick up in minutes - this is by design. It stops at combinators in typescript to solve very specific problem and nothing more. Haskell in ts is not the goal of this npm.