All Projects → lyft → React Javascript To Typescript Transform

lyft / React Javascript To Typescript Transform

Licence: apache-2.0
Convert React JavaScript code to TypeScript with proper typing

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language

Labels

Projects that are alternatives of or similar to React Javascript To Typescript Transform

Libretaxi
Open source Uber #deleteuber
Stars: ✭ 3,687 (+134.1%)
Mutual labels:  lyft
gostats
Go client for Stats
Stars: ✭ 52 (-96.7%)
Mutual labels:  lyft
parallel mAP evaluation
This repo parallelizes mAP_evaluation using python's multiprocessing module.
Stars: ✭ 18 (-98.86%)
Mutual labels:  lyft
omnibot
One slackbot to rule them all
Stars: ✭ 69 (-95.62%)
Mutual labels:  lyft
lyft.github.io
This is code for oss.lyft.com website.
Stars: ✭ 13 (-99.17%)
Mutual labels:  lyft
lyft-node-sdk
Node SDK for the Lyft Public API
Stars: ✭ 15 (-99.05%)
Mutual labels:  lyft
dailycodingproblem
Solutions to Daily Coding Problem questions
Stars: ✭ 26 (-98.35%)
Mutual labels:  lyft
Cartography
Cartography is a Python tool that consolidates infrastructure assets and the relationships between them in an intuitive graph view powered by a Neo4j database.
Stars: ✭ 2,169 (+37.71%)
Mutual labels:  lyft
Scissors
✂ Android image cropping library
Stars: ✭ 1,858 (+17.97%)
Mutual labels:  lyft
Confidant
Confidant: your secret keeper. https://lyft.github.io/confidant
Stars: ✭ 1,666 (+5.78%)
Mutual labels:  lyft

React JavaScript to TypeScript Transform

Build Status

Transforms React code written in JavaScript to TypeScript.

🖥 Download the VSCode Extension

Features:

  • Proxies PropTypes to React.Component generic type and removes PropTypes
  • Provides state typing for React.Component based on initial state and setState() calls in the component
  • Hoist large interfaces for props and state out of React.Component<P, S> into declared types
  • Convert functional components with PropTypes property to TypeScript and uses propTypes to generate function type declaration

Example

input

class MyComponent extends React.Component {
    static propTypes = {
        prop1: React.PropTypes.string.isRequired,
        prop2: React.PropTypes.number,
    };
    constructor() {
        super();
        this.state = { foo: 1, bar: 'str' };
    }
    render() {
        return (
            <div>
                {this.state.foo}, {this.state.bar}, {this.state.baz}
            </div>
        );
    }
    onClick() {
        this.setState({ baz: 3 });
    }
}

output

type MyComponentProps = {
    prop1: string;
    prop2?: number;
};

type MyComponentState = {
    foo: number;
    bar: string;
    baz: number;
};

class MyComponent extends React.Component<MyComponentProps, MyComponentState> {
    constructor() {
        super();
        this.state = { foo: 1, bar: 'str' };
    }
    render() {
        return (
            <div>
                {this.state.foo}, {this.state.bar}, {this.state.baz}
            </div>
        );
    }
    onClick() {
        this.setState({ baz: 3 });
    }
}

Usage

CLI

npm install -g react-js-to-ts
react-js-to-ts my-react-js-file.js

VSCode plugin

details Download from VSCode Marketplace

Development

Tests

Tests are organized in test folder. For each transform there is a folder that contains folders for each test case. Each test case has input.tsx and output.tsx.

npm test

Watch mode

Pass -w to npm test

npm test -- -w

Only a single test case

Pass -t with transform name and case name space separated to npm test

npm test -- -t "react-js-make-props-and-state-transform propless-stateless"
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].