Languages
[Edit]
EN

TypeScript - how to compile ts file to js

17 points
Created by:
cory
1486

In this short article, we would like to show how to compile *.ts files to *.js files.

To complile TypeScript file to JavaScript file, tsc program is necessary. In the below, you will find single output and multiple output compilation descriptions.

Single *.ts file compilation example

Simple steps:

  1. Create script.ts file:
    for (let i = 0; i < 5; ++i) {
        console.log('Hello world!');
    }
  2. Run tsc command:
    tsc script.ts

    or for automatic compilation when script.ts file is changed use:

    tsc -w Script.ts

    Notes:

    • after compliation script.js file should be created,
    • -w parameter enables monitoring and recompilation when file is changed - files watching mode.
  3. Run compiled program
    node Script.js

    Output:

    Hello world!
    Hello world!
    Hello world!
    Hello world!
    Hello world!

Multiple *.ts files to  single *.js file compilation example

Read this article for more details.

 

See also

  1. Installation TypeScript Compiler (tsc)

Alternative titles

  1. TypeScript - how to compile TypeScript file to JavaScript file
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

TypeScript

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join