A command-line tool to convert TypeScript React (TSX) files to plain TypeScript
(TS) files by transforming JSX syntax into React.createElement
calls.
npm install tsx-to-ts
npx tsx-to-ts "src/**/*.tsx"
This will:
- Find all TSX files matching the glob pattern
- Convert JSX syntax to
React.createElement
calls - Save new
.ts
files alongside the original.tsx
files
The tool uses:
acorn
with TypeScript and JSX plugins for parsing- AST transformation to convert JSX elements to
React.createElement
calls recast
for code generation
For example, this TSX:
const Button = () => <button type="submit">Click me</button>;
Gets converted to:
const Button = () =>
React.createElement("button", { type: "submit" } as never, "Click me");
-
Clone the repository
-
Install dependencies:
pnpm install
- Build the project:
pnpm build