How to compile multiple Typescript files into a single file ? (2024)

How to compile multiple Typescript files into a single file? (2)

Approach 1: Compiling multiple Typescript files into a single JavaScript file. We simply use the following syntax:

Syntax:

tsc –out outputFile.js typeScriptFile1.ts typeScriptFile2.ts … typeScriptFilen.ts

Explanation:

  • tsc: It stands for TypeScript compiler which is used to invoke the compiler in order to compile the TypeScript files.
  • –out: It is a CLI (Command Line Interface) command which concatenates the TypeScript files and emits the output to a single JS file.
  • outputFile.js: The JavaScript file which holds the result of the compilation of the TypeScript files.
  • typeScriptFile1, typeScriptFile2 … typeScriptFilen: The TypeScript files to be compiled.

Example: Here, three TypeScript files with the names script.ts, index.ts and app.ts are compiled to a single JavaScript file output.js. Subsequently, the JavaScript file is executed by using the following CLI command:

node output.js
  • script.ts
const myArr = [1, 2, 3, 4, 5];
console.log("CONTENTS OF FILE 1");
for (let i = 0; i < myArr.length; i++) {
console.log(myArr[i]);
}
  • index.ts
const GFG = ["Geeks", "For", "Geeks"];
console.log("\nCONTENTS OF FILE 2");
for (let i = 0; i < GFG.length; i++) {
console.log(GFG[i]);
}
  • app.ts
const geeks = [true, false, 2.5, 5];
console.log("\nCONTENTS OF FILE 3");
for (let i = 0; i < geeks.length; i++) {
console.log(geeks[i]);
}

Generated output JavaScript file “output.js”

  • output.js
var myArr = [1, 2, 3, 4, 5];
console.log("CONTENTS OF FILE 1");
for (var i = 0; i < myArr.length; i++) {
console.log(myArr[i]);
}
var GFG = ["Geeks", "For", "Geeks"];
console.log("\nCONTENTS OF FILE 2");
for (var i = 0; i < GFG.length; i++) {
console.log(GFG[i]);
}
var geeks = [true, false, 2.5, 5];
console.log("\nCONTENTS OF FILE 3");
for (var i = 0; i < geeks.length; i++) {
console.log(geeks[i]);
}

Output:

How to compile multiple Typescript files into a single file? (3)

Approach 2: Compiling multiple Typescript files into a single TypeScript file. We use the following syntax:

Syntax:

tsc –out outputFile.ts typeScriptFile1.ts typeScriptFile2.ts … typeScriptFilen.ts

Explanation:

  • tsc: It stands for TypeScript compiler which is used to invoke the compiler in order to compile the TypeScript files.
  • –out: It is a CLI (Command Line Interface) command which concatenates the TypeScript files and emits the output to a single TypeScript file
  • outputFile.ts: The TypeScript file which holds the result of the compilation of the TypeScript files
  • typeScriptFile1, typeScriptFile2 … typeScriptFilen: The TypeScript files to be compiled.

Example: Here, three TypeScript files with the names file1.ts, file2.ts and file3.ts are compiled to a single TypeScript file output.ts. After that, the resultant TypeScript file is compiled to a JavaScript file output.js and then the JavaScript file is executed by using the following CLI commands:

tsc output.ts
node output.js
  • file1.ts
let i = 1;
console.log("CONTENTS OF FILE 1");
while (i <= 5) {
console.log(i);
i++;
}
  • file2.ts
console.log("\nCONTENTS OF FILE 2");
console.log("GeeksForGeeks is a computer science portal for geeks.");
file3.ts

const geeks = [2, 4, 6, 8];
console.log("\nCONTENTS OF FILE 3");
for (let i = 0; i < geeks.length; i++) {
console.log(geeks[i]);
}

Generated output TypeScript file “output.ts”

  • output.ts
var i = 1;
console.log("CONTENTS OF FILE 1");
while (i <= 5) {
console.log(i);
i++;
}
console.log("\nCONTENTS OF FILE 2");
console.log("GeeksForGeeks is a computer science portal for geeks.");
var geeks = [2, 4, 6, 8];
console.log("\nCONTENTS OF FILE 3");
for (var i_1 = 0; i_1 < geeks.length; i_1++) {
console.log(geeks[i_1]);
}
Generated output JavaScript file "output.js"
output.js

var i = 1;
console.log("CONTENTS OF FILE 1");
while (i <= 5) {
console.log(i);
i++;
}
console.log("\nCONTENTS OF FILE 2");
console.log("GeeksForGeeks is a computer science portal for geeks.");
var geeks = [2, 4, 6, 8];
console.log("\nCONTENTS OF FILE 3");
for (var i_1 = 0; i_1 < geeks.length; i_1++) {
console.log(geeks[i_1]);
}

Output:

How to compile multiple Typescript files into a single file? (4)
How to compile multiple Typescript files into a single file ? (2024)
Top Articles
BBB Tips: How to handle door-to-door sales
Xfinity Internet Plans for Seniors (2024) │The Senior List
Katie Pavlich Bikini Photos
Gamevault Agent
Hocus Pocus Showtimes Near Harkins Theatres Yuma Palms 14
Free Atm For Emerald Card Near Me
Craigslist Mexico Cancun
Hendersonville (Tennessee) – Travel guide at Wikivoyage
Doby's Funeral Home Obituaries
Vardis Olive Garden (Georgioupolis, Kreta) ✈️ inkl. Flug buchen
Select Truck Greensboro
How To Cut Eelgrass Grounded
Pac Man Deviantart
Craigslist In Flagstaff
Shasta County Most Wanted 2022
Energy Healing Conference Utah
Testberichte zu E-Bikes & Fahrrädern von PROPHETE.
Aaa Saugus Ma Appointment
Geometry Review Quiz 5 Answer Key
Walgreens Alma School And Dynamite
Bible Gateway passage: Revelation 3 - New Living Translation
Yisd Home Access Center
Home
Shadbase Get Out Of Jail
Gina Wilson Angle Addition Postulate
Celina Powell Lil Meech Video: A Controversial Encounter Shakes Social Media - Video Reddit Trend
Walmart Pharmacy Near Me Open
Dmv In Anoka
A Christmas Horse - Alison Senxation
Ou Football Brainiacs
Access a Shared Resource | Computing for Arts + Sciences
Pixel Combat Unblocked
Umn Biology
Cvs Sport Physicals
Mercedes W204 Belt Diagram
Rogold Extension
'Conan Exiles' 3.0 Guide: How To Unlock Spells And Sorcery
Teenbeautyfitness
Weekly Math Review Q4 3
Facebook Marketplace Marrero La
Nobodyhome.tv Reddit
Topos De Bolos Engraçados
Gregory (Five Nights at Freddy's)
Grand Valley State University Library Hours
Holzer Athena Portal
Hampton In And Suites Near Me
Stoughton Commuter Rail Schedule
Bedbathandbeyond Flemington Nj
Free Carnival-themed Google Slides & PowerPoint templates
Otter Bustr
San Pedro Sula To Miami Google Flights
Selly Medaline
Latest Posts
Article information

Author: Laurine Ryan

Last Updated:

Views: 5626

Rating: 4.7 / 5 (77 voted)

Reviews: 84% of readers found this page helpful

Author information

Name: Laurine Ryan

Birthday: 1994-12-23

Address: Suite 751 871 Lissette Throughway, West Kittie, NH 41603

Phone: +2366831109631

Job: Sales Producer

Hobby: Creative writing, Motor sports, Do it yourself, Skateboarding, Coffee roasting, Calligraphy, Stand-up comedy

Introduction: My name is Laurine Ryan, I am a adorable, fair, graceful, spotless, gorgeous, homely, cooperative person who loves writing and wants to share my knowledge and understanding with you.