3.1.1 • Published 2 years ago

react-to-typescript-definitions v3.1.1

Weekly downloads
1,352
License
MIT
Repository
github
Last release
2 years ago

react-to-typescript-definitions

GitHub license npm Travis codecovCommitizen friendly Standard Version renovate badge

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:

/**
 * Returns the typescript definition for the given file.
 *
 * @param name The name of the generated module
 * @param path The path to the file to parse
 * @param options The options to use
 * @return The type definition as string
 */
function generateFromFile(name, path, options)
/**
 * Returns the typescript definition for the given source.
 *
 * @param name The name of the generated module
 * @param code The code to parse
 * @param options The options to use
 * @return The type definition as string
 */
function generateFromSource(name, code, options)
/**
 * Returns the typescript definition for the given babylon AST object.
 *
 * @param name The name of the generated module
 * @param ast The babylon ASt to parse
 * @param options The options to use
 * @return The type definition as string
 */
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.
3.1.1

2 years ago

3.1.0

2 years ago

3.0.1

3 years ago

3.0.0

3 years ago

2.0.0

5 years ago

1.2.0

6 years ago

1.1.0

6 years ago

1.0.0

6 years ago

0.28.2

6 years ago

0.28.1

6 years ago

0.28.0

6 years ago

0.27.1

6 years ago

0.27.0

6 years ago

0.26.0

6 years ago

0.25.1

6 years ago

0.25.0

6 years ago

0.24.1

6 years ago

0.24.0

6 years ago

0.23.0

6 years ago

0.22.0

7 years ago

0.21.1

7 years ago

0.21.0

7 years ago

0.20.0

7 years ago

0.19.1

7 years ago

0.19.0

7 years ago

0.18.1

7 years ago

0.18.0

7 years ago

0.17.1

7 years ago

0.17.0

7 years ago

0.16.2

7 years ago

0.16.1

7 years ago

0.16.0

7 years ago

0.15.0

7 years ago

0.14.1

7 years ago

0.14.0

7 years ago

0.13.0

8 years ago

0.12.0

8 years ago

0.11.1

8 years ago

0.11.0

8 years ago

0.10.0

8 years ago

0.9.0

8 years ago

0.8.0

8 years ago

0.7.0

8 years ago

0.6.0

8 years ago

0.5.0

8 years ago

0.4.0

8 years ago

0.3.2

8 years ago

0.3.1

8 years ago

0.3.0

8 years ago

0.2.1

8 years ago

0.1.0

8 years ago