react-to-typescript-definitions
Create typescript definitions files (d.ts) from react components.
Features
- ES6 and ES7 class syntax
- Most PropTypes
- any, array, bool, func, number, object, string, node, element, oneOfType, arrayOf, symbol, shape
- Partial support for oneOf PropType
- required PropTypes
- instanceOf PropTypes (when using API and giving a resolve function)
- jsdoc
Usage
Installation
Install as npm package:
npm install react-to-typescript-definitions --save-dev
or
npm install -g react-to-typescript-definitions
CLI
Usage
$ react2dts [--module-name <name> | --top-level-module]
react2dts reads from stdin to process a file.
Options
--module-name, --name name of the module to create
--top-level-module if the created module should live in top-level
Examples
$ cat <some/react/component.jsx> |react2dts --module-name module-name
$ cat <some/react/component.jsx> |react2dts --top-level-module
API
Functions:
function generateFromFile(name, path, options)
function generateFromSource(name, code, options)
function generateFromAst(name, ast, options)
Options:
- instanceOfResolver
A function which gets a type name (as string) and should return the path
to the file defining the type or undefined if the type is not resolvable.
This function is required to generate instanceOf PropTypes.