JavaScript to TypeScript Converter

Add TypeScript annotations to JavaScript, file by file

Free Online JavaScript to TypeScript Converter

You do not migrate a codebase to TypeScript all at once - you convert one file, fix the types, and move on. This converter gives each file a head start: function signatures and variables come back annotated, with concrete types where the code makes them obvious and honest placeholders where it cannot.

  • Parameters and returns annotated - functions gain : type annotations and a return type
  • Literal types inferred - a const assigned a string literal is typed string, as the example shows
  • Honest placeholders - where a type cannot be inferred, the converter uses any and warns you to review it rather than guessing silently
  • Structure untouched - logic, names, and formatting stay yours; only the annotations are added
Open JavaScript to TypeScript Converter

How to Convert JavaScript to TypeScript

  1. Open the JavaScript to TypeScript converter
  2. Paste a JavaScript file or function
  3. Click "Convert" and review the annotations, especially anything typed any
  4. Copy the result into a .ts file and tighten the types as you go

Example Conversion

Input (JavaScript):

function calculateTotal(price, quantity) {
  return price * quantity;
}

const userName = "Ada";

Output (TypeScript):

function calculateTotal(price: any, quantity: any): any {
  return price * quantity;
}

const userName: string = "Ada";

The converter attaches its own warning to results like this: generated types are a starting point, and parameters typed any deserve a second look.

Common Use Cases

Incremental Migration

Convert utility modules one at a time during a codebase-wide move to TypeScript.

Typing Legacy Code

Get a first draft of types for an untyped file before refining it by hand.

Learning TypeScript

See how familiar JavaScript reads once annotations are added.

Safer Refactors

Annotate a file before changing it, so the compiler can guard the edit.

Related Tools