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
- The TypeScript to JavaScript Converter
- A TypeScript file, or the example ticket queue
Steps
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.
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.Normalstay.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;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.
Common mistakes
- Expecting type errors to be reported
- Types are removed, not checked. Run
tsc --noEmitin 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: