3 ms·
I'm guessing you mean it's similar to the map case? Clojure/Script of course approaches validation and parsing using schema systems (malli or spec) that has it
by fulafel 5y ago
I'm guessing you mean it's similar to the map case?
Clojure/Script of course approaches validation and parsing using schema systems (malli or spec) that has its advantages compared to static type based approaches.
- eyelidlessness 5y agoI mean TypeScript’s structural type system is effectively “just use maps”. With very few exceptions, any structurally equivalent type is substitutable for another. > Clojure/Script of course approaches validation and parsing using schema systems (malli or spec) that has its advantages compared to static type based approaches. So does TypeScript. It has to, because the type system doesn’t have a runtime. The benefit in TS is that you also get static analysis.
- fulafel 5y agoCan you point to some exemplar TS schema system(s) suitable for structured data parsing and validation? I've seen io-ts but it seems quite clunky in comparison, but maybe it's not representative.
- fulafel 5y agoReplying to myself - Zod seems a better TS side library for this.
- eyelidlessness 5y agoYes, I would have pointed to Zod. There are a lot of options in the space, but I think there’s still room for improvement. My (vaporware, but I’ve built something similar before on top of io-ts) project would provide a similar API, but with base types built from JSON Schema definitions, and automatically generate docs. There are also opportunities to significantly improve runtime performance (at the expense of build time) by avoiding unnecessary parsing where statically checked code paths are already valid, eg naive multiple parse steps.
- Waterluvian 5y agoTypescript is fundamentally bad for this because the type system does not exist at runtime. I’ve yet to find one I like so I just hand roll both typings and JSON schema. Particularly because I want the schema for other languages too.