Show HN: Generate TypeScript Types from JSON Samples
1–2 of 2 posts
Re: Show HN: Generate TypeScript Types from JSON Samples
#2The 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
Let me know what you think! In addition to the linked demo, the code is on GitHub:
https://github.com/jvilk/maketypes
And there's an NPM package that contains a command line tool: