{"repo":"ThomasAribart/json-schema-to-ts","free":true,"listed":false,"github":"https://github.com/ThomasAribart/json-schema-to-ts","clone":"git clone https://github.com/ThomasAribart/json-schema-to-ts.git","description":"Infer TS types from JSON schemas 📝","language":"TypeScript","stars":1778,"topics":["json-schema","typescript","json","type","schema","ts"],"license":"MIT","category":"dev-tools","readme_excerpt":"💖 Huge thanks to the sponsors who help me maintain this repo: &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; Stop typing twice 🙅‍♂️ A lot of projects use JSON schemas for runtime data validation along with TypeScript for static type checking. Their code may look like this: Both objects carry similar if not exactly the same information. This is a code duplication that can annoy developers and introduce bugs if not properly maintained. That's when json-schema-to-ts comes to the rescue 💪 FromSchema The FromSchema method lets you infer TS types directly from JSON schemas: Schemas can even be nested, as long as you don't forget the as const statement: The as const statement is used so that TypeScript takes the schema definition to the word (e.g. true is interpreted as the true constant and not widened as boolean ). It is pure TypeScript and has zero impact on the compiled code. If you don't mind impacting the compiled code, you can use the asConst util, which simply returns the schema while narrowing its inferred type. Since TS 4.9, you can also use the satisfies operator to benefit from type-checking and autocompletion: You can also use this with JSDocs by wrapping your schema in / @type {const} @satisfies {import('json-schema-to-ts').JSONSchema} / (...) like: Why use json-schema-to-ts ? If you're looking for runtime validation with added types, libraries like yup, zod or runtypes may suit your needs while being easier to use! On the other hand, ","default_branch":null,"files":null,"tree":[],"storefront":"/r/ThomasAribart","claimed":false,"request_supported":{"post":"https://gitbuyer.com/r/ThomasAribart/json-schema-to-ts/request-supported","requests":0},"note":"indexed from public GitHub; nothing is for sale on this page. Clone it from GitHub. Paid listings live at /search."}