react-prop-types-typescript
Codemod to convert React PropTypes into TypeScript props interfaces.
- Supports function and class components
- Supports
static propTypeson class components - Supports
forwardRefandReact.forwardRef - Supports
React.memo(...)wrappers - Copies JSDoc comments onto generated TypeScript members
- Supports preserving PropTypes with
preserve-prop-types=unconverted|all
Usage
bashnpx codemod react-prop-types-typescript --target <path>
Before
jsximport PropTypes from "prop-types"; import React from "react"; export function MyComponent(props) { return <span />; } MyComponent.propTypes = { bar: PropTypes.string.isRequired, foo: PropTypes.number, };
After
tsximport React from "react"; interface MyComponentProps { bar: string; foo?: number; } export function MyComponent(props: MyComponentProps) { return <span />; }