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

typescript-proptypes-generator

v0.0.6

Published

Export TypeScript interfaces and types in TS files and convert them to PropTypes in generated JS files.

Readme

typescript-proptypes-generator

A library for generically exporting TypeScript interfaces in TS files and converting them to PropTypes in generated JS files.

Use cases

  • Supporting external JS clients or React components that are not written in TypeScript
  • Turn type files generated by graphql schemas into Proptypes for React components

Install

npm install typescript-proptypes-generator --save-dev

Usage

import generate from 'typescript-proptypes-generator';

generate({
  tsConfig: './tsconfig.json',
  prettierConfig: '.prettierrc',
  inputPattern: 'path/to/your/files/*.ts'
});

| Option | Description | Required | |----------------|----------------------------------------------------------------------------------------|-----------| | tsConfig | Relative tsConfig file path for processing TS files | true | | prettierConfig | Relative prettierConfig file path for formatting the generated JS files | false | | inputPattern | Pattern or array of patterns of files to parse for interfaces and convert to proptypes | true | | outputDir | Output directory to put generated JS files in, defaults to adjacent to the input file | false |

Example

input TS file:

// ./interface.ts
export interface TestInterface {
  numericField: number;
  booleanField: boolean;
  objectField: {
    numericField: number;
    booleanField: boolean;
  };
}
import generate from 'typescript-proptypes-generator';

generate({
  tsConfig: './tsconfig.json',
  prettierConfig: '.prettierrc',
  inputPattern: './interface.ts'
});

output JS file:

// ./interface.js
export const TestInterface = {
  booleanField: PropTypes.bool.isRequired,
  numericField: PropTypes.number.isRequired,
  objectField: PropTypes.shape({
    booleanField: PropTypes.bool.isRequired,
    numericField: PropTypes.number.isRequired,
  }).isRequired,
};

What about the typescript-to-proptypes library?

This library uses a modified version of the typescript-to-proptypes API for converting TypeScript definitions to PropTypes. The purpose of that library was to expose an API that clients could use to create their own proptype generation scripts. It did not include a script for generating those interfaces itself.

Clients using the library like Material UI have created scripts for generating prop types for certain scenarios. In that case it is used for taking JS files in a folder structure of:

ReactComponentName
  ReactComponentName.js
  ReactComponentName.d.ts

and mutating the JS file to include auto generated prop types from the declaration file.

The use case for this project is to:

  1. Bundle in a script to do the generation
  2. Not have any coupling to folder structures, declaration files or React components
  3. Not mutate input files

Thank yous

License

This project is licensed under the terms of the MIT license.