Socket
Socket
Sign inDemoInstall

react-to-typescript-definitions

Package Overview
Dependencies
203
Maintainers
2
Versions
51
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    react-to-typescript-definitions

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


Version published
Maintainers
2
Install size
11.9 MB
Created

Changelog

Source

3.1.1 (2022-06-07)

Bug Fixes

  • upgrade astq (db5a2f9)

Readme

Source

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.

FAQs

Last updated on 07 Jun 2022

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc