Skip to content

jcenturion/proptypes-to-ts-declarations

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Proptypes to TypeScript Declarations [beta]

Creates TS declarations from your components library.

Usage

Install it:

$ npm install proptypes-to-ts-declarations

Using it:

const propTypesToTS = require('proptypes-to-ts-declarations');

propTypesToTS(
  'my-library',
  './src/components/**/*.js',
  './index.d.ts');

Example

Input

const MyComponent = (props) => (
  <div className={props.className}>
    Good {props.time}, {props.name}!
  </div>
);

MyComponent.propTypes = {
  className: PropTypes.string
  time: PropTypes.oneOf(['morning', 'afternoon']).isRequired,
  name: PropTypes.string.isRequired
};

Output

declare module "my-library" {
  import * as React from "react";

  type timeEnum =
    | "default"
    | "information"
    | "success"
    | "warning"
    | "danger";

  export interface my_component_props {
    className?: string;
    time: timeEnum;
    name: string;
  }

  export const MyComponent: React.ComponentClass<my_component_props>;
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published