Registry /
devtools / json-schema-to-typescript-nullable
Install & Compatibility
Where this runs
No compatibility data collected yet for this library.
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
compile
✓ import { compile } from 'json-schema-to-typescript'
✗ const compile = require('json-schema-to-typescript').compile;
Requires ESM or TypeScript. CommonJS require works but not recommended.
compileFromFile
✓ import { compileFromFile } from 'json-schema-to-typescript'
✗ const compileFromFile = require('json-schema-to-typescript').compileFromFile;
Same as compile, file-based input.
compile
✓ const { compile } = require('json-schema-to-typescript');
✗ const compile = require('json-schema-to-typescript');
Default export is not the compile function; destructure required.
Compiles a JSON Schema object to a TypeScript interface and writes to file.
import { compile } from 'json-schema-to-typescript';
import * as fs from 'fs';
const schema = {
title: 'User',
type: 'object',
properties: {
name: { type: 'string' },
age: { type: 'integer' }
},
required: ['name']
};
compile(schema, 'User').then((ts) => fs.writeFileSync('user.d.ts', ts));
Errors
Common errors & fixes
TypeError: Cannot destructure property 'compile' of 'undefined' or null.
Trying to import default export as named import.
fixUse named import: `import { compile } from 'json-schema-to-typescript'`. Error: Cannot find module 'prettier'
Prettier is not installed.
fixInstall prettier: `npm install prettier` or set `format: false`.
Error: No schema provided
Empty or undefined schema object passed to compile().
fixEnsure schema is a valid JSON Schema object.
Audit
Dependencies
@apidevtools/json-schema-ref-parserrequiredResolves $ref references in schemas
prettierrequiredFormats generated TypeScript code