6 ms·
Io-to: both static and dynamic type checking for JSON API data in TypeScript
- girvo 9y agoLooks nice; I use “decoders” with Flow for this use case myself. Can even avoid doubling up in type/parsing definitions by deriving the type of the result via inference, from the decoder. Excited to play with this for my TypeScript projects.
- latchkey 9y agoThis is nice, but I'd prefer to use mobx-state-tree to reason about models and the logic around them. The ability to use middleware to implement things like undo [1], is really powerful. [1] https://github.com/mobxjs/mobx-state-tree/tree/master/packages/mst-middlewares https://github.com/mobxjs/mobx-state-tree/tree/master/packag...
- pducks32 9y agoThis is awesome. I was looking for this a few weeks ago and found a library I don’t love. This feels right for Typescript and I’m going to add it to a big project like immediately. Great job to the authors!
- untog 9y agoAn alternative I'm a fan of: using typescript-json-schema: https://github.com/YousefED/typescript-json-schema https://github.com/YousefED/typescript-json-schema To turn TypeScript interfaces into JSON schemas, then evaluating incoming JSON using whatever JSON schema validation library you want. It's a tradeoff though, as this replaces the need for "t.TypeOf" with some kind of separate build step that creates the schemas. I still prefer it though, as it allows me to use standard TS interfaces rather than any kind of custom format.
- miga 9y agoNice to see another feature of TypeScript that PureScript and Elm had for years. I will certainly use it tomorrow! (Unless I use typescript-json-schema, which is awesome too!)