tsx-to-ts
v1.1.1
Published
A tool to convert TSX files to TS files
Downloads
323
Readme
tsx-to-ts
A command-line tool to convert TypeScript React (TSX) files to plain TypeScript
(TS) files by transforming JSX syntax into React.createElement
calls.
Installation
npm install tsx-to-ts
Usage
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
How it Works
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");
Development
Clone the repository
Install dependencies:
pnpm install
- Build the project:
pnpm build