TypeScript - how to compile ts file to js

14 points
Created by:

To complile TypeScript file to JavaScript file tsc programm is necessary.

1. Single *.ts file compilation example

  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 on Script.ts file changed use:

    $ tsc -w Script.ts


    • after compliation Script.js file should be created
    • -w parameter enables file changed watching
  3. Run compiled program
    $ node Script.js


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

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

Read this article for more details.

Checkout latest findings & news:

Checkout latest questions:

Checkout latest wiki articles:

Hey 👋
Would you like to know what we do?
  • Dirask is a friendly IT community for learners, professionals and hobbyists to share their knowledge and help each other in extraordinary easy way.
  • We welcome everyone,
    no matter what the experience,
    no matter how basic the question is,
    this community will help you.
Rockstar community members
Thank you for great work 👍