Languages
[Edit]
EN

TypeScript - how to compile ts file to js

14 points
Created by:
Kate_C
19800

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

    Notes:

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

    Output:

    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.

Native Advertising
50 000 ad impressions - 449$
🚀
Get your tech brand or product in front of software developers.
For more information contact us:
Red dot
Dirask - friendly IT community for everyone.

❤️💻 🙂

Join