js-to-ts-converter-cli
v1.0.3
Published
A JS to TS/TSX converter CLI with JSX detection and destructured params fix
Downloads
25
Readme
JS → TS/TSX Converter CLI
A CLI tool to convert JavaScript (JS/JSX) files to fully TypeScript-compliant TS/TSX files.
This tool automatically:
- Adds type annotations for variables and function parameters
- Converts destructured function parameters to
params: anywith destructuring inside the function - Skips type annotations on
for...inandfor...ofloop variables - Infers basic types for literals, arrays, and objects
- Detects JSX in files and outputs
.tsxfiles - Removes
.js,.jsx,.ts,.tsxextensions from import statements
GitHub
https://github.com/sivaprasath2004/js-to-ts-converter
Features
- ✅ Converts JS/JSX files to TS/TSX
- ✅ Automatically infers types for variables
- ✅ Fixes destructured function parameters
- ✅ Fully TypeScript-compliant output
- ✅ Preserves JSX when present
- ✅ Cleans import statements (removes file extensions)
Installation
Install globally via npm:
npm install -g js-to-ts-converter-cliOr test locally:
npm linkUsage
Convert a single file:
js-to-ts-converter ./src/utils.jsConvert a folder:
js-to-ts-converter ./srcOutput files are generated in the tsConverter folder inside the source directory.
Examples
JS File: utils.js
function add({ a, b }) {
return a + b;
}
const multiply = (x, y) => x * y;
import App from './App.js';Converted TS File: tsConverter/utils.ts
function add(params: any): any {
const { a, b } = params;
return a + b;
}
const multiply = (x: any, y: any): any => x * y;
import App from './App';Notes
- Detects JSX automatically: converts
.jsto.tsxif JSX is present - Works with
.js,.jsx,.ts,.tsxfiles - Skips folders like
node_modules,public,web_pack,.erb
