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

Arrow left icon
Profile Icon Dubois Profile Icon Georges
Arrow right icon
R$50 per month
Full star icon Full star icon Full star icon Full star icon Full star icon 5 (4 Ratings)
Paperback Nov 2019 804 pages 1st Edition
eBook
R$49.99 R$213.99
Paperback
R$267.99
Subscription
Free Trial
Renews at R$50p/m
Arrow left icon
Profile Icon Dubois Profile Icon Georges
Arrow right icon
R$50 per month
Full star icon Full star icon Full star icon Full star icon Full star icon 5 (4 Ratings)
Paperback Nov 2019 804 pages 1st Edition
eBook
R$49.99 R$213.99
Paperback
R$267.99
Subscription
Free Trial
Renews at R$50p/m
eBook
R$49.99 R$213.99
Paperback
R$267.99
Subscription
Free Trial
Renews at R$50p/m

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
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 : 9781789615869
Vendor :
Microsoft
Category :
Languages :
Tools :

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details

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

Packt Subscriptions

See our plans and pricing
Modal Close icon
R$50 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
R$500 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 R$25 each
Feature tick icon Exclusive print discounts
R$800 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 R$25 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total R$ 759.97
Advanced TypeScript Programming Projects
R$245.99
Learn TypeScript 3 by Building Web Applications
R$267.99
The JavaScript Workshop
R$245.99
Total R$ 759.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

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.