TypeScript to JavaScript Converter · Tutorial

How to convert a TypeScript file to plain JavaScript

5 min readbeginnerUpdated

You may need plain JavaScript from a TypeScript file, for a project without a build step or to share with someone. You will convert a ticket queue class and see how each TypeScript feature is handled.

What you need

Steps

  1. Load the file

    Press Try it to load the example: a type import, an enum, an interface and a class with a private parameter property and typed methods.

  2. See the types disappear

    The interface and the type import are gone, and parameters and return types have no annotations. Default values such as Priority.Normal stay.

  3. Look at the enum and constructor

    The enum becomes an object that maps names to numbers and back, and the parameter property becomes an assignment in the constructor.

    constructor(team) {
        this.team = team;
  4. Pick a target and module format

    Keep ES2020 and ES modules for modern browsers and Node.js, or choose CommonJS if the code will be loaded with require().

Try it yourself

Opens the TypeScript to JavaScript Converter with this tutorial's sample loaded.

Try it now

Common mistakes

Expecting type errors to be reported
Types are removed, not checked. Run tsc --noEmit in your project to find type errors.
Converting files one by one for a whole project
For many files, use your project's build. This page suits single files and snippets.

Next steps

Go back to the TypeScript to JavaScript Converter, or keep going with one of these: