Skip to content

Options

json-schema-to-typescript is very flexible, you can customise it with options.

Compile Options

compileFromFile and compile accept options as their last argument (all keys are optional):

additionalProperties

Default value for additionalProperties, when it is not explicitly set.

Default: true

bannerComment

Disclaimer comment prepended to the top of each generated file.

When no banner specified, it adds:

ts
/* eslint-disable */
/**
 * This file was automatically generated by json-schema-to-typescript.
 * DO NOT MODIFY IT BY HAND. Instead, modify the source JSON Schema file,
 * and regenerate this file.
 */

customName

Custom function to provide a type name for a given schema.

cwd

Root directory for resolving $ref

Default: process.cwd()

declareExternallyReferenced

When enabled, declare external schemas referenced via $ref.

enableConstEnums

When enabled, prepend enums with const.

Default: true

inferStringEnumKeysFromValues

Create enums from JSON enums with eponymous keys.

Default: false

ignoreMinAndMaxItems

Ignore maxItems and minItems for array types, preventing tuples being generated.

Default: false

maxItems

Maximum number of unioned tuples to emit when representing bounded-size array types, before falling back to emitting unbounded arrays. Increase this to improve precision of emitted types, decrease it to improve performance, or set it to -1 to ignore maxItems.

Default: 20

strictIndexSignatures

Append all index signatures with | undefined so that they are strictly typed.

Default: false

style

A Prettier configuration.

The default configurations:

js
{
  bracketSpacing: false,
  printWidth: 120,
  semi: true,
  singleQuote: false,
  tabWidth: 2,
  trailingComma: 'none',
  useTabs: false
}

unknownAny

Use unknown instead of any where possible.

Default: false

unreachableDefinitions

Generates code for $defs that aren't referenced by the schema.

Default: false

$refOptions

$RefParser Options, used when resolving $refs