{"library":"schema-typescript","title":"JSON Schema to TypeScript Converter","description":"This package facilitates the automatic conversion of JSON Schema definitions into TypeScript interfaces and types. It is currently at version 0.14.3 and appears to be actively maintained, with its last publish occurring four days ago as of the current date, indicating a relatively frequent release cadence. A key differentiator is its robust handling of standard JSON Schema features like `$ref` and `$defs` for modular schema definitions, and its ability to process arrays of defined types seamlessly into TypeScript arrays. Unlike some alternative tools that focus on generating JSON Schema *from* TypeScript code, this library specifically targets the generation of TypeScript *from* existing JSON Schema, providing a critical tool for schema-first development workflows. It operates with minimal dependencies and is part of the broader `constructive-io/dev-utils` monorepo, although it is designed for general-purpose use.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install schema-typescript"],"cli":null},"imports":["import { generateTypeScript } from 'schema-typescript';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { generateTypeScript } from 'schema-typescript';\nimport * as fs from 'node:fs/promises';\n\nconst userSchema = {\n  \"$id\": \"https://example.com/user.schema.json\",\n  \"$schema\": \"http://json-schema.org/draft-07/schema#\",\n  \"title\": \"User\",\n  \"type\": \"object\",\n  \"properties\": {\n    \"id\": {\n      \"type\": \"string\",\n      \"format\": \"uuid\"\n    },\n    \"name\": {\n      \"type\": \"string\",\n      \"description\": \"Full name of the user\"\n    },\n    \"email\": {\n      \"type\": \"string\",\n      \"format\": \"email\"\n    },\n    \"age\": {\n      \"type\": \"integer\",\n      \"minimum\": 0,\n      \"maximum\": 150\n    },\n    \"isActive\": {\n      \"type\": \"boolean\",\n      \"default\": true\n    }\n  },\n  \"required\": [\"id\", \"name\", \"email\"]\n};\n\nasync function generateUserTypes() {\n  try {\n    const tsDefinition = await generateTypeScript(userSchema, 'User');\n    await fs.writeFile('src/types/user.d.ts', tsDefinition);\n    console.log('TypeScript types for User generated successfully to src/types/user.d.ts');\n    console.log('\\nGenerated TypeScript:\\n', tsDefinition);\n  } catch (error) {\n    console.error('Failed to generate TypeScript types:', error);\n  }\n}\n\ngenerateUserTypes();","lang":"typescript","description":"This quickstart demonstrates how to import the `generateTypeScript` function and convert a sample JSON Schema object for a 'User' into a TypeScript interface string, then write it to a file.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}