
Show HN: Generate TypeScript Types from JSON Samples - jvilk
https://jvilk.com/MakeTypes/
======
jvilk
I wrote a library and command line tool that generates TypeScript types for
JSON objects from samples. It can also generate "proxy" objects that typecheck
JSON objects at runtime, so you can code against JSON services without fear!

The use cases include:

* (Types) Generating quick-and-dirty TypeScript types for a web service or other JSON service you are coding against using response samples in its documentation.

* (Proxies) Ensuring that your code fails reliably when a service returns a JSON object with data that you do not expect. (Otherwise, your code may chug on with an undefined value and fail in a weird place!)

The generated proxies are also useful for non-TypeScript code when compiled to
plain ole JavaScript.

To generate types from samples, I adapted the technique used in the F# Data
library, which is described in the following paper:

[https://dl.acm.org/citation.cfm?id=2908115](https://dl.acm.org/citation.cfm?id=2908115)

Let me know what you think! In addition to the linked demo, the code is on
GitHub:

[https://github.com/jvilk/maketypes](https://github.com/jvilk/maketypes)

And there's an NPM package that contains a command line tool:

[https://www.npmjs.com/package/maketypes](https://www.npmjs.com/package/maketypes)

