Registry / devtools / json-schema-to-typescript-nullable

json-schema-to-typescript-nullable

JSON →
library10.1.3jsnpmunverified

Compile JSON Schema to TypeScript typings, with support for nullable types. Version 10.1.3. Stable release, actively maintained. Key differentiators: CLI tool, customizable output via Prettier style options, and support for $ref resolution, strict index signatures, and unknown type. Compatible with Node >=10.

npm install json-schema-to-typescript-nullable
INSTALL
IMPORT
SIG · JSON-SCHEMA-TO-TYP
J
json-schema-to-typescript-nullable
devtoolsjavascriptv10.1.3
harness data pending
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));
Debug
Known issues
breakingIn v10, the default value for `unknownAny` changed from `false` to `true`, causing `any` types to become `unknown`.
fix
Set `unknownAny: false` in options if previous behavior is needed.
affects: >=10.0.0
gotchaThe library uses Prettier for formatting; if Prettier is not installed, formatting may fail silently or produce unformatted output.
fix
Install Prettier as a dependency or set `format: false`.
affects: >=1.0.0
deprecatedThe `$refOptions` option is deprecated in favor of using `refOptions` (lowercase r).
fix
Use `refOptions` instead.
affects: >=10.0.0
Errors
Common errors & fixes
TypeError: Cannot destructure property 'compile' of 'undefined' or null.
Trying to import default export as named import.
fix
Use named import: `import { compile } from 'json-schema-to-typescript'`.
Error: Cannot find module 'prettier'
Prettier is not installed.
fix
Install prettier: `npm install prettier` or set `format: false`.
Error: No schema provided
Empty or undefined schema object passed to compile().
fix
Ensure schema is a valid JSON Schema object.
Upgrade
Version history
10.1.3latest on npm
Audit
Dependencies
@apidevtools/json-schema-ref-parserrequiredResolves $ref references in schemas
prettierrequiredFormats generated TypeScript code
Agent activity
29 hits · last 30 days
node
24
Resources
json-schema-to-typescript-nullable — npm install json-schema-to-typescript-nullable · libregistry