TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Show HN: Generate TypeScript Types from JSON Samples

5 点作者 jvilk超过 8 年前

1 comment

jvilk超过 8 年前
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>