Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Arrow up icon
GO TO TOP
Learn TypeScript 3 by Building Web Applications

You're reading from   Learn TypeScript 3 by Building Web Applications Gain a solid understanding of TypeScript, Angular, Vue, React, and NestJS

Arrow left icon
Product type Paperback
Published in Nov 2019
Publisher Packt
ISBN-13 9781789615869
Length 804 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Authors (2):
Arrow left icon
 Dubois Dubois
Author Profile Icon Dubois
Dubois
 Georges Georges
Author Profile Icon Georges
Georges
Arrow right icon
View More author details
Toc

Table of Contents (15) Chapters Close

Preface 1. Introduction to TypeScript 2. Building TodoIt - Your Own Web Application with TypeScript FREE CHAPTER 3. Improving TodoIt with Classes and Interfaces 4. Leveraging Generics and Enums 5. Coding WorldExplorer to Explore the Population of the World 6. Introduction to Testing 7. Discovering Angular, Angular Material, and RxJS 8. Rewriting MediaMan Using Angular and Angular Material 9. Introducing Vue.js 10. Creating LyricsFinder with Vue.js 11. Diving into React, NestJS, GraphQL, and Apollo 12. Revisiting LyricsFinder 13. What's Next? 14. Other Books You May Enjoy

Compiling manually using the TypeScript compiler

Now let’s try to use tsc (the TypeScript compiler) to manually compile our code.
Go back to the Terminal and run tsc:

As you can see, there are many options. You can list all the available options using tsc --all. We'll discover some of those as we go about building cool applications together but, for now, let's focus on the task at hand: compiling a single file. You can do this by executing tsc hello-world.ts.

If all goes well, you should see nothing. But TypeScript should have transpiled your code to JavaScript.

By convention, TypeScript generates a .js file with the same name as the input file, right next to it. If you list the directory contents, you should see the newly added file:

$ ls
total 2.0K
drwxr-xr-x 1 dsebastien 197121 0 Sep 25 15:42 .
drwxr-xr-x 1 dsebastien 197121 0 Sep 25 14:07 ..
drwxr-xr-x 1 dsebastien 197121 0 Sep 25 14:16 .vscode
-rw-r--r-- 1 dsebastien 197121 100 Sep 25 15:42 hello-world.js <-----
-rw-r--r-- 1 dsebastien 197121 104 Sep 25 15:29 hello-world.ts

Let's see what TypeScript has generated for us:

var hello = "Hello world";
function say(something) {
console.log(something);
}
say(hello);

This is, apart from whitespace, the exact same code. Captain Obvious again here, but indeed, since we have given JavaScript code as input to TypeScript's compiler, it didn't have much to do for us. This was just a tease; now let's make use of the TypeScript type system!

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Modal Close icon
Modal Close icon