npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

jsonschema-ts-type

v1.0.1

Published

TypeScript Type Helper to convert JSONSchema to TypeScript Type

Readme

jsonschema-ts-type

This package provide a helper Type Schema which will covert the JSONSchema type into TypeScript type. Note the JSONSchema must be literal typed to make this helper Type Schema to be able to parse the Schema correctly, the JSONSchema must stay in .ts file and followed as const instead of .json file since the .json file will result in generic types like string or number.

Difference compared to json-schema-to-typescript?

This package have no running code! It's just a TypeScript generic type which will convert the JSONSchema from literal typed JSON to a TypeScript type. By using json-schema-to-typescript, The JSONSchema is converted to .d.ts from CLI or programmatically way, by using this package, the JSONSchema definitions stay in the .ts file and the type is converted by TypeScript generic typing system.

Should I use this one instead of json-schema-to-typescript?

If you have been using json-schema-to-typescript in your project already, you should continue use it since it's much more reliable. If it's new to your project you may try this one, but use it at your own risk, it may be broken on complex JSONSchema since it costs too much for the TypeScript compiler. Again, json-schema-to-typescript is more reliable.

How to use

This package can be used like this:

import {Schema} from 'jsonschema-ts-type';

const schemaObj = {
  description: 'Any validation failures are shown in the right-hand Messages pane.',
  type: 'object',
  properties: {
    foo: {
      type: 'number',
    },
    bar: {
      type: 'string',
      enum: ['a', 'b', 'c'],
    },
  },
  additionalProperties: false,
} as const; // Note: `as const` is required to turn the type into literal type

type TypeObj = Schema<typeof schemaObj>;
// The TypeObj will be {foo?: number; bar?: "a" | "b" | "c"}

Which JSONSchema features are supported

The following features of JSONSchema are supported to be converted into TypeScript Type:

  • Primitive type (not the limitation like minium, pattern cannot be applied).
  • Array Type (both generic array and Tuple, but contains, minItems, maxItems and uniqueItems are not supported)
  • Object Type (patternProperties are not supported, additionalProperties cannot be parsed to specific type, name, size and dependencies are also not supported)
  • Enumerated values and constant value
  • anyOf combination keyword, note allOf, oneOf and not are not supported
  • $ref, note only absolute path is supported, URI pattern ("definitions.json#/address") and id based location ("$ref": "#address") are not supported

Contribution

Clone this repo and open it with VSCode, everything should be working properly. Please add the generic type in src folder and add related test cases in test folder.