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

Hello world with TypeScript

Now that you have all the tools at your disposal, let's write the ceremonial Hello World in TypeScript.

Creating the project

Open your favorite Terminal (again, we will assume Bash here). Create a new folder called hello-world:

$ mkdir hello-world

After the previous command, you can go into the newly created folder:

$ cd hello-world

Now open VS Code in the current folder using the code . command.

Hello (Type/Java)Script!

So, TypeScript is a superset of JavaScript, right? Let's see what that actually means by following these steps:

  1. Create a new file called hello-world.ts:
The .ts file extension stands for TypeScript.

You can do it from within VS Code:

As you can see, VS Code directly recognizes TypeScript files:

  1. Now add the following code to your newly created file:
var hello = "Hello world";

function say(something) {
console.log(something);
}

say(hello);

Now let's do a silly thing: let's ask Node (our JavaScript interpreter) to execute our TypeScript code:

$ node hello-world.ts 

The output will be as follows:

That worked? Well, as you have probably guessed, this first example only contains JavaScript, which is why node doesn't have any issue.

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