{"id":14893,"library":"rm-json-schema-to-typescript","title":"JSON Schema to TypeScript (Forked)","description":"The `rm-json-schema-to-typescript` package is a fork of the popular `json-schema-to-typescript` library, designed to compile JSON schemas into TypeScript interfaces and typings. Currently at version 10.2.0, this package offers modified reference resolving behavior compared to its upstream counterpart. Its development status is tied to the original project, with an explicit intention to be deprecated once the core changes implemented in this fork are accepted into the main `json-schema-to-typescript` repository. As a fork, its release cadence is likely reactive to critical fixes or its specific feature set rather than a strict schedule. It aims to provide a drop-in replacement where its altered reference resolution is beneficial, but users should be aware of its temporary nature and plan for eventual migration.","status":"deprecated","version":"10.2.0","language":"javascript","source_language":"en","source_url":"https://github.com/bcherny/json-schema-to-typescript","tags":["javascript","json","schema","typescript","compile","transpile","api","interface","typing"],"install":[{"cmd":"npm install rm-json-schema-to-typescript","lang":"bash","label":"npm"},{"cmd":"yarn add rm-json-schema-to-typescript","lang":"bash","label":"yarn"},{"cmd":"pnpm add rm-json-schema-to-typescript","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The npm package is `rm-json-schema-to-typescript`, but the import path shown in the provided documentation is `json-schema-to-typescript`. This implies it's a drop-in replacement using the original's module name. Always verify the actual import path for the installed package.","wrong":"const { compile } = require('json-schema-to-typescript')","symbol":"compile","correct":"import { compile } from 'json-schema-to-typescript'"},{"note":"Similar to `compile`, the import path refers to the original package name. Ensure your `package.json` correctly points to `rm-json-schema-to-typescript` if using this fork.","wrong":"import { compileFromFile } from 'rm-json-schema-to-typescript'","symbol":"compileFromFile","correct":"import { compileFromFile } from 'json-schema-to-typescript'"},{"note":"Type imports for configuration options are available. The options object can modify behavior like banner comments, `$ref` resolution, or Prettier formatting.","symbol":"Options","correct":"import type { Options } from 'json-schema-to-typescript'"}],"quickstart":{"code":"import { compile, compileFromFile } from 'json-schema-to-typescript';\nimport * as fs from 'fs/promises';\n\n// Define a simple JSON schema programmatically\nconst mySchema = {\n  title: 'UserSchema',\n  type: 'object',\n  properties: {\n    id: { type: 'string', format: 'uuid' },\n    name: { type: 'string' },\n    email: { type: 'string', format: 'email' },\n    isActive: { type: 'boolean', default: true }\n  },\n  required: ['id', 'name', 'email'],\n  additionalProperties: false\n};\n\nasync function generateTypes() {\n  try {\n    // Compile from a JS object in memory\n    const tsFromObject = await compile(mySchema, 'UserSchema');\n    console.log('Generated from object:\\n', tsFromObject);\n    // For demonstration, write to a dummy file. In real use, this might be dynamic.\n    await fs.writeFile('user.d.ts', tsFromObject);\n\n    // Example of compiling from a file (assuming 'example.json' exists)\n    // For a real scenario, you'd create this file first.\n    // const tsFromFile = await compileFromFile('example.json');\n    // await fs.writeFile('example.d.ts', tsFromFile);\n\n    console.log('TypeScript types generated successfully.');\n  } catch (error) {\n    console.error('Error generating types:', error);\n  }\n}\n\ngenerateTypes();","lang":"typescript","description":"This quickstart demonstrates how to compile a JSON schema object into a TypeScript interface using the `compile` function, and how it writes the output to a file."},"warnings":[{"fix":"Monitor the original `json-schema-to-typescript` project for updates that incorporate the `rm-json-schema-to-typescript` fork's features. If no upstream merge occurs, consider migrating to another active JSON Schema to TypeScript solution or maintaining a custom fork.","message":"This `rm-json-schema-to-typescript` package is a fork and is explicitly slated for deprecation once its specific changes are accepted into the upstream `json-schema-to-typescript` project. Users should treat it as a temporary solution and plan for migration.","severity":"deprecated","affected_versions":">=10.0.0"},{"fix":"Thoroughly review generated TypeScript types if migrating from or to the original `json-schema-to-typescript` package, especially for schemas with external or complex internal `$ref`erences. Test the output against expected type definitions.","message":"This fork specifically features 'changed reference resolving' compared to the original `json-schema-to-typescript`. This modification may lead to different output typings for schemas that rely on complex `$ref` patterns.","severity":"gotcha","affected_versions":">=10.0.0"},{"fix":"When installing via npm as `rm-json-schema-to-typescript`, ensure your import statements in code use `import { ... } from 'json-schema-to-typescript'` as per the documentation. If issues arise, explicitly check your project's module resolution settings or the `package.json` `exports` field of the installed package.","message":"Despite the npm package name being `rm-json-schema-to-typescript`, the provided documentation and code examples suggest importing symbols from `'json-schema-to-typescript'`. This discrepancy can cause confusion and potential module resolution errors if not handled correctly.","severity":"gotcha","affected_versions":">=10.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Ensure `rm-json-schema-to-typescript` is correctly installed. Based on the documentation, try `import { compile } from 'json-schema-to-typescript'` even if you installed the `rm-` prefixed package. Verify your `tsconfig.json` or module resolution settings if problems persist.","cause":"The package `rm-json-schema-to-typescript` is installed, but the import path in the code might be incorrect or the module resolver cannot find the aliased module.","error":"Error: Cannot find module 'json-schema-to-typescript'"},{"fix":"Validate your JSON Schema against the JSON Schema specification (e.g., using a linter or online validator) to ensure it is correctly structured. Check the file path for `compileFromFile`.","cause":"The input provided to `compile` or `compileFromFile` is not a valid JSON Schema object or a path to a valid JSON Schema file.","error":"TypeError: Schema must be an object or boolean"},{"fix":"Review the `$ref` definitions in your JSON schema for circular dependencies. If using external `$ref`s, ensure the `cwd` option in `compile` or `compileFromFile` options correctly points to the base directory for resolution.","cause":"The JSON schema contains circular `$ref`erences that the parser cannot resolve, or the `cwd` option for resolving external references is incorrect.","error":"Error: $ref cycle detected"}],"ecosystem":"npm"}