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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

Show HN: TypeScript Editor that generates structured forms from TypeScript types

12 点作者 fwouts将近 3 年前
Hey HN!<p>I&#x27;ve been doing a lot of work with the TypeScript Compiler API[1] recently as part of my work on Preview.js[2], an IDE extension that lets you preview React&#x2F;Solid&#x2F;Vue components.<p>One thing I noticed is that even with great autocomplete and type validation, creating&#x2F;editing JS values that match a given TypeScript type can require a lot of typing. This is especially the case in Preview.js, where you can edit the props you pass to the component you&#x27;re previewing in the bottom right panel. For example, quickly switching between different variants of a union type can be a hassle.<p>To solve this, I decided to try creating a tool that generates a structured from for a given TypeScript type. For example if you pass it `type Foo = { bar: string, baz: number }`, it will show you a form with two inputs `bar` and `baz` with the appropriate types, and it will output the equivalent JS code (or JSON) as you type.<p>You can try it at <a href="https:&#x2F;&#x2F;tseditor.fwouts.com" rel="nofollow">https:&#x2F;&#x2F;tseditor.fwouts.com</a><p>I built this as a standalone tool so that I could debug it easily (and indeed, I found a ton of great bugs!). As it took shape, I realised there might be other use cases for it than Preview.js. Imagine for example using this in Postman (or whichever tool is better than Postman these days!) instead of inputting JSON values for your request payloads. Or perhaps using this for ad-hoc forms (the form is effectively encoded in the URL).<p>I&#x27;m curious what you&#x27;d see yourself using this editor for? Any feedback welcome of course!<p>Thanks<p>François (@fwouts on Twitter)<p>[1] <a href="https:&#x2F;&#x2F;github.com&#x2F;microsoft&#x2F;TypeScript&#x2F;wiki&#x2F;Using-the-Compiler-API" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;microsoft&#x2F;TypeScript&#x2F;wiki&#x2F;Using-the-Compi...</a> [2] <a href="https:&#x2F;&#x2F;previewjs.com" rel="nofollow">https:&#x2F;&#x2F;previewjs.com</a>

3 条评论

kadrian12将近 3 年前
Wow, this is really great! I&#x27;ve got this case very often when I need non-technical people to send me data in a JSON format, but trying to teach them what JSON is and how to edit it is impossible &#x2F; takes way too much time.<p>This is SO close to the solution I need. If I could configure this form using typescript and then send them a link where they can&#x27;t see or edit the typescript, but just fill out the form and send me the JSON, that would be incredible!!
评论 #32271849 未加载
评论 #32272182 未加载
armchairhacker将近 3 年前
This is really nice and it actually supports a lot of the complex types TypeScript allows (e.g. array of unions, functions). Would also be cool if you could generate random values and function inputs for QuickCheck &#x2F; regression test generation
评论 #32258806 未加载
评论 #32271990 未加载
Existenceblinks将近 3 年前
The optional and random value buttons are nice. Does Typescript have tagged union? Would love too see how it looks like.<p>I have an app doing almost the same except it has its own schema editor, not typescript, work directly with ast.
评论 #32274356 未加载