包详细信息

react-to-typescript-definitions

KnisterPeter12.8kMIT3.1.1

Create typescript definitions files (d.ts) from react components

自述文件

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.

更新日志

Changelog

All notable changes to this project will be documented in this file. See standard-version for commit guidelines.

3.1.1 (2022-06-07)

Bug Fixes

3.1.0 (2021-11-12)

Features

  • create definitions for components exported as object with component properties (38603a0)
  • create intersection types for components with dot notation component members (40bccb0)

3.0.1 (2021-04-07)

Bug Fixes

  • handle nested string literal props (46edf00)

3.0.0 (2021-03-22)

⚠ BREAKING CHANGES

  • Drop support for node 8

Features

  • parse files which uses optional chaining feature (3432de8)

Bug Fixes

  • deps: update dependency dts-dom to v3.4.0 (d87a65e)
  • deps: update dependency dts-dom to v3.5.0 (1c87f5c)
  • deps: update dependency dts-dom to v3.6.0 (4aa8889)
  • deps: update dependency meow to v6.0.1 (8967eb7)
  • deps: update dependency meow to v6.1.0 (8ce686d)
  • correctly import pascalcase function (686bd9f)
  • deps: update dependency pascal-case to v3 (ca6fecc)
  • correct usage of execa (ccb4699)
  • deps: update dependency chalk to v3 (963d6fc)
  • deps: update dependency dts-dom to v3.3.0 (49135b1)
  • deps: update dependency meow to v6 (435ae07)
  • deps: update dependency strip-ansi to v6 (fd7e788)

  • drop support for node 8 (ca0a130)

2.0.0 (2019-05-17)

Bug Fixes

  • deps: remove stubbed strip-ansi typings, use default import (75f59b6)
  • deps: update dependency chalk to v2.4.2 (dd31c7e)
  • deps: update dependency dts-dom to v3.1.1 (5c20f13)
  • deps: update dependency dts-dom to v3.2.0 (e4ad59c)
  • deps: update dependency get-stdin to v7 (61fb667)
  • deps: update dependency strip-ansi to v5 (a321237)
  • deps: update dependency strip-ansi to v5.1.0 (7d6aee4)
  • deps: update dependency strip-ansi to v5.2.0 (5360d26)
  • remove unused variable (70dace6)

chore

BREAKING CHANGES

  • drop support for node6

1.2.0 (2018-09-26)

Features

  • allow users to set additional babylon plugins (9798c08)

1.1.0 (2018-08-16)

Bug Fixes

  • deps: update dependency astq to v2.2.10 (a9c27c7)
  • deps: update dependency astq to v2.3.1 (e9d58aa)
  • deps: update dependency astq to v2.3.3 (c6a5f97)
  • deps: update dependency astq to v2.3.4 (3d077de)
  • deps: update dependency astq to v2.3.6 (0064a64)
  • deps: update dependency babel-generator to v6.26.1 (ff30c67)
  • deps: update dependency babylon to v7.0.0-beta.47 (ab95114)
  • deps: update dependency chalk to v2.4.1 (e4980fc)
  • deps: update dependency dts-dom to v3.1.0 (1d79303)

Features

1.0.0 (2018-04-26)

Bug Fixes

  • deps: update dependency babylon to v7.0.0-beta.41 (9b5736d)
  • deps: update dependency babylon to v7.0.0-beta.42 (48902cc)
  • deps: update dependency babylon to v7.0.0-beta.44 (b77411e)
  • deps: update dependency babylon to v7.0.0-beta.46 (a7939dd)
  • deps: update dependency dts-dom to ^3.0.0 (56b1012)
  • deps: update dependency meow to v5 (d48b698)

Chores

BREAKING CHANGES

  • drop node4 support

0.28.2 (2018-03-14)

Bug Fixes

  • deps: update dependency babylon to v7.0.0-beta.40 (75bd5f6)
  • deps: update dependency get-stdin to ^6.0.0 (aa579ea)
  • for SFCs export a const and not a type (173eeb7)

0.28.1 (2018-02-23)

0.28.0 (2018-02-07)

Bug Fixes

  • avoid any for oneOf arrays with identifiers (f947a23)

Features

  • support generating types for PureComponents (7343af1)

0.27.1 (2018-01-23)

Bug Fixes

  • package: update dts-dom to version 1.0.0 (7a7cd1b)
  • for SFCs use triple slash directive instead of react import (9b1096d), closes #469 #471

0.27.0 (2018-01-20)

Bug Fixes

  • add parentheses around function in union by updating dts-dom (baaa644)
  • add react import to SFC typings (2f53d2e)

Features

  • support named exports as default (67064b8)

0.26.0 (2018-01-19)

Bug Fixes

  • add react import to SFC typings (2f53d2e)

Features

  • support named exports as default (67064b8)

0.25.1 (2018-01-16)

Bug Fixes

  • remove typeof from instanceOf and symbol prop types (e3d0467)

0.25.0 (2018-01-15)

Features

  • support any name for namespace import of prop-types (fe26b1e)
  • support named imports from prop-types (c7df614)

0.24.1 (2018-01-12)

Bug Fixes

  • npm: add "types" entry to package.json (b71c964)

0.24.0 (2017-12-12)

Bug Fixes

  • package: update babylon to version 7.0.0-beta.34 (7d1dee1), closes #448
  • package: update meow to version 4.0.0 (f7768a4)

Features

0.23.0 (2017-11-22)

Bug Fixes

  • package: update babylon to version 6.17.0 (17a6d25)
  • package: update babylon to version 6.17.1 (d6742f9)
  • package: update babylon to version 7.0.0-beta.31 (fc60b2c)
  • package: update babylon to version 7.0.0-beta.32 (6d79609)
  • package: update babylon to version 7.0.0-beta.9 (91bdfc3)
  • package: update chalk to version 2.0.1 (85d37ff), closes #408
  • package: update chalk to version 2.1.0 (e11c8d6)
  • package: update strip-ansi to version 4.0.0 (a138ce7)

Features

0.22.0 (2017-04-18)

Features

  • resolve referenced propTypes (da9863b)

0.21.1 (2017-04-16)

Bug Fixes

  • package: update astq to version 2.0.1 (fa1178b)
  • package: update babel-generator to version 6.24.1 (8887bb5)
  • handle named export specifiers (beced3b), closes #368

0.21.0 (2017-04-03)

Bug Fixes

  • package: update dts-dom to version 0.1.17 (03e7ef6)
  • handle unnamed default export (a0be64e), closes #350
  • package: update dts-dom to version 0.1.18 (1405400)

Features

  • support output for react-like libraries (0ed6ffc), closes #351

0.20.0 (2017-03-21)

Bug Fixes

  • package: update babel-generator to version 6.24.0 (20b8840)
  • package: update dts-dom to version 0.1.16 (2b0cf25)
  • package: update pascal-case to version 2.0.1 (fe8ad84)

Features

  • handle array props with shapes in extractComplexTypes (efb0fa8)

0.19.1 (2017-03-02)

Bug Fixes

  • fix and improve error output (c3d79b6)

0.19.0 (2017-03-01)

Bug Fixes

  • package: update babylon to version 6.16.0 (24e3da1)
  • package: update babylon to version 6.16.1 (c2064f0)
  • package: update dts-dom to version 0.1.13 (2630ab8)
  • package: update dts-dom to version 0.1.14 (#295) (859c134)
  • package: update dts-dom to version 0.1.15 (75d5775)

Features

  • report error context and source excerpt (251a46a)
  • retain error information (e24f500)

0.18.1 (2017-01-27)

Bug Fixes

  • replace all newlines (7a7153b)
  • typings: handle one more type of es6 exports (#287) (3d3cfad)

0.18.0 (2017-01-11)

Bug Fixes

  • package: update babylon to version 6.15.0 (#269) (8bb7da2)

Features

  • export complex types as type aliases or interfaces (#272) (95215cd)

0.17.1 (2017-01-09)

Bug Fixes

  • handle references for shapes correctly (#262) (cc4b6f9)

0.17.0 (2016-11-22)

Features

  • resolve references in oneOf propTypes (#236) (4e85be2), closes #236

0.16.2 (2016-11-07)

Bug Fixes

  • enum-types should fallback to any (0fa1fa7)

0.16.1 (2016-11-07)

Bug Fixes

  • do not fail in case of inference errors (#223) (078b97d)

0.16.0 (2016-11-04)

Features

  • add partial support for onOf propType (#218) (d6d7d1e)
  • add support for symbol propType (c2a2542)
  • implement shape propType (#219) (6876062)

0.15.0 (2016-11-03)

Features

  • write multiple outputs per file (#211) (f6f63ae)

0.14.1 (2016-11-01)

Bug Fixes

  • allow empty or non-export input files (#213) (1dca59c), closes #212

0.14.0 (2016-10-31)

Features

  • add support for stateless function components (#204) (c7a988b)

0.13.0 (2016-10-20)

Features

  • parsing: Add ability to parse babeled files (#121) (a19c80c)

0.12.0 (2016-05-25)

Features

  • Adds option create write typings to top-level (#116) (a4cb090)

0.11.1 (2016-05-06)

0.11.0 (2016-04-09)

Bug Fixes

  • parser: configure babel to be as permissive as possible (586b5ec)

0.10.0 (2016-02-01)

Features

  • Added support for ref attributes (d6f5b46)

0.9.0 (2016-01-29)

0.8.0 (2016-01-21)

Features

  • Exported component interfaces (511767d)

0.7.0 (2015-12-31)

Features

  • Support es6 class syntax (8b27145)

0.6.0 (2015-12-21)

Features

  • Added instanceOf proptypes (c548b7b)
  • Added jsdoc to d.ts files (1a40858)

0.5.0 (2015-12-21)

Features

0.4.0 (2015-12-19)

Features

  • Added react key to generated props (a54511e)

Performance Improvements

  • Tests are written in typescript (2b04aa6)

0.3.2 (2015-12-15)

Performance Improvements

  • Reduced indention depth (d981864)

0.3.1 (2015-12-10)

Bug Fixes

  • Terminate node if no input from stdin (61734ca)

0.3.0 (2015-12-10)

Bug Fixes

  • CHANGELOG: Fixed changelog urls (5aa784d)

Features

  • types: Added explicit any type (d06dc20)
  • types: Added more optional types (5ab5736)
  • Implemented pipes (2c4b42a)

0.2.1 (2015-12-02)

Bug Fixes

  • main: Fixed mail file attribute (c694f3e)
  • npm: Fixed publishing (28c64d8)

0.2.0 (2015-12-02)