• Version 14.1.0
  • Published
  • 197 kB
  • 12 dependencies
  • MIT license


npm i json-schema-to-typescript
yarn add json-schema-to-typescript
pnpm add json-schema-to-typescript


compile json schema to typescript typings




const DEFAULT_OPTIONS: Options;


    function compile

    compile: (
    schema: JSONSchema4,
    name: string,
    options?: Partial<Options>
    ) => Promise<string>;

      function compileFromFile

      compileFromFile: (
      filename: string,
      options?: Partial<Options>
      ) => Promise<string>;


        class ValidationError

        class ValidationError extends Error {}


          interface CustomTypeJSONSchema

          interface CustomTypeJSONSchema extends NormalizedJSONSchema {}

            property tsType

            tsType: string;

              interface EnumJSONSchema

              interface EnumJSONSchema extends NormalizedJSONSchema {}

                property enum

                enum: JSONSchema4Type[];

                  interface JSONSchema

                  interface JSONSchema extends JSONSchema4 {}

                    property deprecated

                    deprecated?: boolean;
                    • property exists at least in https://json-schema.org/draft/2019-09/json-schema-validation.html#rfc.section.9.3

                    property tsEnumNames

                    tsEnumNames?: string[];
                    • schema extension to support numeric enums

                    property tsType

                    tsType?: string;
                    • schema extension to support custom types

                    interface NamedEnumJSONSchema

                    interface NamedEnumJSONSchema extends NormalizedJSONSchema {}

                      property tsEnumNames

                      tsEnumNames: string[];

                        interface Options

                        interface Options {}

                          property $refOptions

                          $refOptions: $RefOptions;
                          • [$RefParser](https://github.com/APIDevTools/json-schema-ref-parser) Options, used when resolving $refs

                          property additionalProperties

                          additionalProperties: boolean;
                          • Default value for additionalProperties, when it is not explicitly set.

                          property bannerComment

                          bannerComment: string;
                          • Disclaimer comment prepended to the top of each generated file.

                          property customName

                          customName?: (
                          schema: LinkedJSONSchema,
                          keyNameFromDefinition: string | undefined
                          ) => string | undefined;
                          • Custom function to provide a type name for a given schema

                          property cwd

                          cwd: string;
                          • Root directory for resolving [$ref](https://tools.ietf.org/id/draft-pbryan-zyp-json-ref-03.html)s.

                          property declareExternallyReferenced

                          declareExternallyReferenced: boolean;
                          • Declare external schemas referenced via $ref?

                          property enableConstEnums

                          enableConstEnums: boolean;
                          • Prepend enums with [const](https://www.typescriptlang.org/docs/handbook/enums.html#computed-and-constant-members)?

                          property format

                          format: boolean;
                          • Format code? Set this to false to improve performance.

                          property ignoreMinAndMaxItems

                          ignoreMinAndMaxItems: boolean;
                          • Ignore maxItems and minItems for array types, preventing tuples being generated.

                          property inferStringEnumKeysFromValues

                          inferStringEnumKeysFromValues: boolean;
                          • Create enums from JSON enums with eponymous keys

                          property maxItems

                          maxItems: number;
                          • 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 minItems and maxItems.

                          property strictIndexSignatures

                          strictIndexSignatures: boolean;
                          • Append all index signatures with | undefined so that they are strictly typed.

                            This is required to be compatible with strictNullChecks.

                          property style

                          style: PrettierOptions;
                          • A [Prettier](https://prettier.io/docs/en/options.html) configuration.

                          property unknownAny

                          unknownAny: boolean;
                          • Generate unknown type instead of any

                          property unreachableDefinitions

                          unreachableDefinitions: boolean;
                          • Generate code for definitions that aren't referenced by the schema?

                          Package Files (2)

                          Dependencies (12)

                          Dev Dependencies (20)

                          Peer Dependencies (0)

                          No peer dependencies.


                          To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

                          You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/json-schema-to-typescript.

                          • Markdown
                          • HTML
                            <a href="https://www.jsdocs.io/package/json-schema-to-typescript"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>