TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Show HN: Generate TypeScript Types from JSON Samples

5 pointsby jvilkover 8 years ago

1 comment

jvilkover 8 years ago
I wrote a library and command line tool that generates TypeScript types for JSON objects from samples. It can also generate &quot;proxy&quot; objects that typecheck JSON objects at runtime, so you can code against JSON services without fear!<p>The use cases include:<p>* (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.<p>* (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!)<p>The generated proxies are also useful for non-TypeScript code when compiled to plain ole JavaScript.<p>To generate types from samples, I adapted the technique used in the F# Data library, which is described in the following paper:<p><a href="https:&#x2F;&#x2F;dl.acm.org&#x2F;citation.cfm?id=2908115" rel="nofollow">https:&#x2F;&#x2F;dl.acm.org&#x2F;citation.cfm?id=2908115</a><p>Let me know what you think! In addition to the linked demo, the code is on GitHub:<p><a href="https:&#x2F;&#x2F;github.com&#x2F;jvilk&#x2F;maketypes" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;jvilk&#x2F;maketypes</a><p>And there&#x27;s an NPM package that contains a command line tool:<p><a href="https:&#x2F;&#x2F;www.npmjs.com&#x2F;package&#x2F;maketypes" rel="nofollow">https:&#x2F;&#x2F;www.npmjs.com&#x2F;package&#x2F;maketypes</a>