3 ms·
So proptypes can be inspected at runtime. Does anyone have any success with tools that can turn Typescript types into runtime walkable datastructures or do code
by benjaminjackman 9y ago
So proptypes can be inspected at runtime. Does anyone have any success with tools that can turn Typescript types into runtime walkable datastructures or do code-
generation / execute macros based on them as part of the build process?
I use typescript quite a bit and am starting to hit some patterns that could be abstracted nicely if metaprogramming tools were in the shed.
- dvdsgl 9y agoquicktype (https://app.quicktype.io/ https://app.quicktype.io/) can generate TypeScript types from JSON, Schema, and GraphQL, and it also emits a runtime type representation to do dynamic typechecking. Perhaps this isn't exactly what you're looking for but you could easily modify it to generate whatever code you'd like. We have an experimental Handlebar-based templating feature to make customizing the generated code easier.
- joe-stanton 9y agoYou might be interested in this: https://github.com/gcanti/io-ts https://github.com/gcanti/io-ts and many related projects by Giulio.
- joe-stanton 9y agoBeforehand I built something very similar to what you described for Flow (https://hackernoon.com/runtime-introspection-of-flow-types-ddb7e5b042a5 https://hackernoon.com/runtime-introspection-of-flow-types-d...). Many others superseded this implementation, the above being one example.
- tehno 9y agoThere's also very similar project at https://github.com/pelotom/runtypes https://github.com/pelotom/runtypes that our company uses. Don't have enough experience with it yet to say which is better, io-ts on runtypes.