Registry
Ccodemod-com-bot avatar

react-prop-types-typescript

Convert React PropTypes declarations into TypeScript props interfaces

codemod-com-bot57,057 executions

  • React
  • PropTypes
  • TypeScript
Connect a repo
npx codemod react-prop-types-typescript

react-prop-types-typescript

Codemod to convert React PropTypes into TypeScript props interfaces.

  • Supports function and class components
  • Supports static propTypes on class components
  • Supports forwardRef and React.forwardRef
  • Supports React.memo(...) wrappers
  • Copies JSDoc comments onto generated TypeScript members
  • Supports preserving PropTypes with preserve-prop-types=unconverted|all

Usage

bash
npx codemod react-prop-types-typescript --target <path>

Before

jsx
import PropTypes from "prop-types";
import React from "react";

export function MyComponent(props) {
  return <span />;
}

MyComponent.propTypes = {
  bar: PropTypes.string.isRequired,
  foo: PropTypes.number,
};

After

tsx
import React from "react";

interface MyComponentProps {
  bar: string;
  foo?: number;
}

export function MyComponent(props: MyComponentProps) {
  return <span />;
}

Ready to evolve your codebase?

Build tailored, compiler-aware skills to assess, plan, and automate complex codebase changes.