MJS TS
File conversion

Convert MJS to TS

QUICK ANSWER
Is it possible to convert MJS to TS?
Yes - MJS converts to TS.

Rename file.mjs to file.ts and it is already valid TypeScript, since existing JavaScript is legal TS. You then add type annotations where the compiler flags errors, and tsc compiles it back to JavaScript for running.

Also to TS: REC · JS · TRP

On this page

Tested on macOS, Windows & Linux
Last verified Sep 2026

More free converters

HEIC, PNG, WEBP, MP3 and more - every tool here is free.

Open the toolbox

Why convert MJS to TS?

Developers convert .mjs to .ts to gain static type checking and editor autocompletion while keeping the same ES-module structure they already wrote.

How to convert MJS to TS

TypeScript compiler (tsc) OPEN-SOURCE

Set "allowJs": true in tsconfig.json, then run tsc to type-check and emit JavaScript; tighten strict once errors are resolved.

Visual Studio Code FREE

Open the renamed .ts in VS Code; its built-in TypeScript service surfaces missing types and quick-fixes to add annotations.

esbuild OPEN-SOURCE

Run esbuild file.ts --outfile=file.js to strip the types fast for a build, though esbuild does not type-check.

About these formats

Quality & what to watch

  • Renaming makes the file valid TS, but it gains no real safety until you add annotations and enable strict checks.
  • tsc reports type errors that plain JavaScript ignored, so you may need to fix implicit any and untyped imports.
  • esbuild transpiles without type-checking, so use tsc --noEmit alongside it to actually catch type errors.

Frequently asked questions

Is `.mjs` valid TypeScript?
Yes. TypeScript is a superset of JavaScript, so a renamed .mjs compiles as .ts even before you add any type annotations.
Should I use `.ts` or `.mts`?
Use .mts when you want the output to stay an ES module regardless of package.json. Use .ts and let tsconfig.json and the package type decide.
Do my imports still work?
Yes, ESM import/export syntax carries over unchanged into TypeScript. You only add type information on top of it.
How do I run the resulting TypeScript?
Compile it with tsc to JavaScript and run that, or use a runner like tsx or ts-node that transpiles on the fly.