Paste JavaScript code and get a TypeScript version with type annotations added. Handles function parameters, variable types, var replacement, and require() imports. Best-effort — complex logic needs manual review.
string, number, boolean, unknown[], and Record from initializer values: unknown to untyped function parameters in both declaration and arrow function syntaxrequire() calls to ES module import statements.ts file ready to drop into your TypeScript project
TypeScript is a superset of JavaScript, which means all valid JavaScript is also valid TypeScript. The migration process is not about rewriting code — it is about adding type information so the TypeScript compiler can catch type errors at build time rather than at runtime. The most common first steps are renaming .js files to .ts, replacing var with let or const, converting CommonJS require() calls to ES module imports, and adding type annotations to function parameters that TypeScript cannot infer.
TypeScript can infer types from variable initializers: if you write const count = 0, TypeScript knows count is a number without an explicit annotation. The places where manual annotations are most needed are function parameters (TypeScript cannot infer what callers will pass), empty array and object literals (TypeScript infers never[] and {} without guidance), and function return types when the return value is complex.
For large codebases, TypeScript's allowJs and checkJs compiler options let you migrate incrementally — JavaScript files continue to work alongside TypeScript files, and you can convert one module at a time. Setting "strict": true in tsconfig.json enables the full set of type checks that catch the most bugs. This tool handles the mechanical transformations that are the same in every migration — the domain-specific type modeling is where human judgment is always required.
var declarations with let. You may want to change some of these to const where the variable is never reassigned.string, number literals → number, booleans → boolean, [] → unknown[], {} → Record<string, unknown>, null → null.: unknown to unannotated parameters in function declarations and arrow functions. Parameters already annotated are left unchanged.const x = require('mod') to import x from 'mod' and const {a, b} = require('mod') to import {a, b} from 'mod'.