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
Learn TypeScript 3 by Building Web Applications
Learn TypeScript 3 by Building Web Applications

Learn TypeScript 3 by Building Web Applications: Gain a solid understanding of TypeScript, Angular, Vue, React, and NestJS

eBook
€8.99 €28.99
Paperback
€35.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Product feature icon AI Assistant (beta) to help accelerate your learning
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

Learn TypeScript 3 by Building Web Applications

Building TodoIt - Your Own Web Application with TypeScript

In this chapter, we are going to build our first application together. It won't take over the world (yet), but it will certainly help you to become more familiar with TypeScript's basic features.

Building this first concrete application will give us the chance to look at many TypeScript concepts.

We'll also take the opportunity to learn about npm with its package.json configuration file, as well as tsc (the TypeScript compiler) and the tsconfig.json configuration file.

What will you build?

It has now become a rite of passage for developers learning new programming languages and frameworks, so we will abide and build a todo (that is, task) management web application that we'll call TodoIt.

TodoIt will have the following features:

  • Add a new todo item
  • List existing todo items
  • Filter the list of existing todo items
  • Remove a single todo item
  • Remove all todo items

Creating the project using npm

First things first, let's create the project as follows:

  1. Open your favorite shell.
  2. Create a new folder called todoit-v1.
  3. Go into the newly created folder.
  4. Create the project using the npm init command.

When you execute the following npm init command, npm will request some input to properly configure the project:

$ npm init
This utility will walk you through creating a package.json file.
It only covers the most common items, and tries to guess sensible defaults.

Execute `npm help json` to get a more comprehensive description of these fields.

Use `npm install <pkg>` afterwards to install a package and
save it as a dependency in the package.json file.

Press ^C at any time to quit.
...

The following are the different inputs that npm will request. Just press the Enter key multiple times as we will not need to change the defaults:

package name: ...

Introducing npm

As we saw in the first chapter, npm (or yarn if you prefer that alternative package manager) will become one of your best friends. With it, you will be able to manage the dependencies of your projects, install and update them, and execute scripts as well.

package.json

When you work on a project, usually, you simply don't want to create a long document explaining how to download/install each and every dependency. Instead, you want to have a simple way to install everything at once.

As explained in the official documentation (https://docs.npmjs.com/getting-started/using-a-package.json), a package.json file does the following:

  • Lists the packages that your project depends on
  • Allows you to specify the versions...

Adding TypeScript to the project

Now that you're more familiar with npm, let's add TypeScript to our project. As discussed in the last section, we'll add it to the package.json file and then we will also add a script to invoke it easily.

First, add the devDependencies section and add TypeScript to those dependencies (since TypeScript is a tool and is only necessary at build time):

"devDependencies": {
"typescript": "3.4.4" },
As we've already mentioned before, you can search for npm packages on the official website: https://www.npmjs.com. In the case of TypeScript, the package is located here: https://www.npmjs.com/package/typescript.

Next, replace the scripts section with the following:

"scripts": { 
    "compile": "tsc" 
}, 

With this script, we will be able to easily invoke the TypeScript version...

Configuring the TypeScript compiler

Now that everything is set up with npm, we can turn our focus to TypeScript.

Typically, the first thing to do in any TypeScript project is to create the compiler configuration file. So, indeed, at this point, you need to be aware of the fact that the TypeScript compiler can be configured through a file called tsconfig.json. The presence of a tsconfig.json file in a folder tells TypeScript that the folder is the root of a TypeScript project.

Through tsconfig.json, you can precisely configure the compiler, adapting it to your project and its specific needs.

To get started, create a default configuration file using npm run compile -- --init.

Do you remember npm <script_name> -- <arguments>? This is how you can pass arguments to the programs executed by your npm scripts. If you don't like that approach, then you can...

Creating the TodoIt application

You should now have a good starting point with both npm and TypeScript configured. If you're not sure or something went wrong, then you can start here with the initial code that we have provided with the book's sample code. You can find it in the Chapter02 folder (corresponding to the second chapter) and in the todoit-v1-initial folder.

In the initial project, we've called the compile script tsc for simplicity, but you can name it as you prefer. This is why we use npm run tsc in the following examples instead of npm run compile.

Ready? Great, let's write our application and learn some more together!

Opening the project in VS Code

Go to the project's folder and open VS...

Debugging your code in the web browser

Usually, you shouldn't get into a lot of trouble while coding the examples in this book. But, of course, in the typical day of any software developer, there will be many times where things go awry and where a good debugging session will help.

Let's see how you can debug web applications. This is a must-have skill for any developer out there, and there are many tools and solutions to help you figure out what your programs are doing.

The most basic debugging tool at your disposal is simply the console.log function, which you can use to log variables while your program executes. Although, it clearly isn't a panacea and far from a best practice, so you should use it sparingly for small checks. When your code reaches production, you don't want it to be cluttered with console.log statements. Debugging and logging are two separate...

Debugging your code in VS Code

Another interesting alternative to debug your code is to make use of the VS Code debugger.

As with Chrome, you can define breakpoints by clicking next to a line:

Once done, you can start debugging by going to Debug | Start Debugging or by pressing F5:

The first time that you do so, VS Code will create a .vscode/launch.json file for you. This file tells VS Code what to do when it starts a debugging session. In our case, we can leverage the fact that we have Browsersync running in the background and adapt the configuration to let VS Code open Chrome (or another browser) and go to http://localhost:3000 instead of the default 8080 port. Once adapted, the file should look as follows:

{ 
    // Use IntelliSense to learn about possible attributes. 
    // Hover to view descriptions of existing attributes. 
    // For more information, visit: https:...

Generating source maps for easier debugging

One thing that you might have noticed while we were using the debugging in the web browser before is that we only had access to the JavaScript code (as opposed to the TypeScript code when debugging with VS Code directly). In our case, with TodoIt, it is okay because the program is very simple, and so it remains intuitive. But in larger applications, this will simply not be usable.

This is why a feature called source maps is really, really valuable. Source maps are mapping files that create the link between lines in the JavaScript sources and the corresponding ones in the original source code (TypeScript source code, in our case).

Source maps can either be stored in the JavaScript files themselves, in which case, they are called inline source maps or in the separate (that is, external) .map files.

We won't dive much more into the...

Summary

In this chapter, you have built your very first web application with TypeScript.

TodoIt is quite basic, but by building it you should now have a better understanding of how useful TypeScript is during development and how easy it is to configure its compiler through tsconfig.json. Along the way, you have learned about some additional TypeScript concepts, such as type declarations, type annotations, arrays handling, the null special type, the as cast operator, lambda expressions, and the different types of loops supported in TypeScript.

Also, you should now have a good understanding of npm, package.json, dependency management, and defining and executing scripts with npm.

We have explained what Browsersync is and how to integrate it into your project to get live reloading during development.

In addition, we have seen how to use VS Code to develop with TypeScript and how to...

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Create modern Web applications to help businesses around the world benefit from better quality applications
  • Learn the latest features of TypeScript 3 and use them wisely
  • Explore TDD practices, OOP techniques, and industry best practices to create high-quality and modular apps

Description

TypeScript is a superset of the JavaScript programming language, giving developers a tool to help them write faster, cleaner JavaScript. With the help of its powerful static type system and other powerful tools and techniques it allows developers to write modern JavaScript applications. This book is a practical guide to learn the TypeScript programming language. It covers from the very basics to the more advanced concepts, while explaining many design patterns, techniques, frameworks, libraries and tools along the way. You will also learn a ton about modern web frameworks like Angular, Vue.js and React, and you will build cool web applications using those. This book also covers modern front-end development tooling such as Node.js, npm, yarn, Webpack, Parcel, Jest, and many others. Throughout the book, you will also discover and make use of the most recent additions of the language introduced by TypeScript 3 such as new types enforcing explicit checks, flexible and scalable ways of project structuring, and many more breaking changes. By the end of this book, you will be ready to use TypeScript in your own projects and will also have a concrete view of the current frontend software development landscape.

Who is this book for?

This book is for software developers who are willing to discover what TypeScript is and how to leverage it to write great quality software. Developers that are already familiar with TypeScript will find this book useful by learning the languages featured introduced by most recent releases. Basic knowledge of the JavaScript programming is expected.

What you will learn

  • Understand and take advantage of TypeScript s powerful Type System
  • Grasp the key concepts and features of Angular, React, Vue.js, and NestJS
  • Handle asynchronous processes using Promises, async/await, Fetch, RxJS, and more
  • Delve into REST, GraphQL and create APIs using Apollo
  • Discover testing concepts, techniques, and tools like TDD, BDD, E2E, Jest
  • Learn Object-Oriented and Functional Programming concepts and leverage those with TypeScript
  • Explore design practices and patterns such as SOLID, MVC, DI and IoC, LoD, AOP, and more

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Nov 22, 2019
Length: 804 pages
Edition : 1st
Language : English
ISBN-13 : 9781789617863
Vendor :
Microsoft
Category :
Languages :
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Product feature icon AI Assistant (beta) to help accelerate your learning
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Nov 22, 2019
Length: 804 pages
Edition : 1st
Language : English
ISBN-13 : 9781789617863
Vendor :
Microsoft
Category :
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
€189.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts
€264.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 101.97
Advanced TypeScript Programming Projects
€32.99
Learn TypeScript 3 by Building Web Applications
€35.99
The JavaScript Workshop
€32.99
Total 101.97 Stars icon
Banner background image

Table of Contents

14 Chapters
Introduction to TypeScript Chevron down icon Chevron up icon
Building TodoIt - Your Own Web Application with TypeScript Chevron down icon Chevron up icon
Improving TodoIt with Classes and Interfaces Chevron down icon Chevron up icon
Leveraging Generics and Enums Chevron down icon Chevron up icon
Coding WorldExplorer to Explore the Population of the World Chevron down icon Chevron up icon
Introduction to Testing Chevron down icon Chevron up icon
Discovering Angular, Angular Material, and RxJS Chevron down icon Chevron up icon
Rewriting MediaMan Using Angular and Angular Material Chevron down icon Chevron up icon
Introducing Vue.js Chevron down icon Chevron up icon
Creating LyricsFinder with Vue.js Chevron down icon Chevron up icon
Diving into React, NestJS, GraphQL, and Apollo Chevron down icon Chevron up icon
Revisiting LyricsFinder Chevron down icon Chevron up icon
What's Next? Chevron down icon Chevron up icon
Other Books You May Enjoy Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Full star icon Full star icon 5
(4 Ratings)
5 star 100%
4 star 0%
3 star 0%
2 star 0%
1 star 0%
Paul Feb 12, 2020
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Très bon livre.
Amazon Verified review Amazon
Nicolas Bruyère Jan 02, 2020
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I really, really enjoyed this book. I came away feeling both knowledgeable and enthusiastic about TypeScript.1. It's perfectly paced for the seasoned programmer who wants to learn TypeScript fast, without getting bogged down in basic programming concepts.2. The explanations are clear. There were times when I had to read a section a couple of times to understand it, particularly around advanced concepts; but this was generally due to the material itself, not to the manner in which it was communicated.3. It was very thorough. I came away feeling that I had all the language and ecosystem-related knowledge required to use TypeScript confidently in production.4. It covered not only the language, but also the ecosystem. The build system for TypeScript projects is inherently more complicated than for many other languages. There are many knobs and levers that can be adjusted. This book provides very clear and helpful advice about how to configure your build based on the requirements of your project.5. The author has an enthusiastic writing style which contains just the right amount things.6. For those who wants to cry out loud they're hanging out with typescript, this bible (800+ pages) is massive and will be the king on his thrown in your library.
Amazon Verified review Amazon
Christopher Cortes Dec 09, 2019
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I am very pleased to present this Learn Typescript 3 by Building Web Applications book, in which I have gladly participated as technical reviewer. As such, I would like to share how extremely valuable I believe a developer will find it and why I consider it to be a must-read.This book will provide any front-end developer with in depth knowledge on the latest features available in this language, that will definitely help him/her to improve the quality of his/her code by making it type-safe, flexible and, at the same time, scalable. Not only he/she will find in this manual the advanced features of Typescript that make it such a great language, so clearly explained, but also several sample applications that, apart from illustrating the different concepts, could be applicable in real life.The added value of this book is that it provides strong foundations on design patterns, techniques, libraries and tooling around Typescript and the front-end ecosystem in general, that are nowadays a must for every developer (front-end, full-stack and even back-end).On top of that, it also offers a basic introduction to the most popular frameworks, such as Angular, React and Vue for the front-end, and NestJS for the back-end, as well as libraries such as Redux, GraphQL and Apollo.I can only recommend it to any developer eager to discover the latest features of Typescript while having fun building nice and realistic applications and, at the same time, using the latest standards and technologies.
Amazon Verified review Amazon
M. Aug 04, 2021
Full star icon Full star icon Full star icon Full star icon Full star icon 5
One of the best overview I have seen explaining clearly the different ways to do with Typescript. I recommend it.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.