Reader small image

You're reading from  Mastering TypeScript - Fourth Edition

Product typeBook
Published inApr 2021
Reading LevelIntermediate
PublisherPackt
ISBN-139781800564732
Edition4th Edition
Languages
Right arrow
Author (1)
Nathan Rozentals
Nathan Rozentals
author image
Nathan Rozentals

Nathan Rozentals has been writing commercial software for over 30 years, in C, C++, Java and C#. He picked up TypeScript within a week after its initial release in October 2012 and realized how much TypeScript could help when writing JavaScript. He was one of the first people to start blogging about TypeScript, discussing early frameworks such as Backbone, Marionette, ExtJS and AngularJs. He knew he'd hit the mark when Microsoft staff started to reference his blog posts in their CodePlex discussion forums. Nathan's TypeScript solutions now control User Interfaces in IoT devices, run as stand-alone applications for Point-of-Sale solutions, provide complex application configuration web sites, and are used for mission-critical server APIs.
Read more about Nathan Rozentals

Right arrow

Preface

The TypeScript language and compiler has been a huge success story since its release in late 2012. It quickly carved out a solid footprint in the JavaScript development community, and continues to go from strength to strength. The language has broken into top ten lists of both popular programming languages, and languages most sought after by companies looking to employ programmers.

Many large-scale JavaScript projects, realizing that their JavaScript code base is becoming unwieldy, have made the decision to switch their code base from JavaScript to TypeScript. In 2014, the Microsoft and Google teams announced that Angular 2.0 would be developed using TypeScript, thereby merging Google's AtScript language and Microsoft's TypeScript languages into one. Angular is now one of the top three most popular Single-Page Application frameworks, and has progressed to version 11.

This large-scale industry adoption of TypeScript shows the value of the language, the flexibility of the compiler, and the productivity gains that can be realized with its rich development toolset. On top of this industry support, the ECMAScript standards are being ratified and published on a yearly basis, therefore introducing new language elements quite rapidly. TypeScript provides a way to use features of these standards in our applications today.

Writing TypeScript applications has been made even more appealing with the large collection of declaration files that have been built by the TypeScript community. These declaration files seamlessly integrate a large range of existing JavaScript frameworks into the TypeScript development environment, bringing with them increased productivity, early error detection, and advanced IntelliSense features. Many JavaScript libraries are now automatically bundling TypeScript types into their releases, meaning that there is first-class support from the library developers, who recognize that a large portion of their user base is using TypeScript.

In the end, TypeScript generates JavaScript. This means that wherever we can use JavaScript, we can use TypeScript.

Who this book is for

Whether you are a developer wanting to learn TypeScript, or an experienced JavaScript or TypeScript developer wanting to take your skills to the next level, this book is for you.

It is a guide for beginners, and also provides practical insights and techniques for experienced JavaScript and TypeScript programmers. No prior knowledge of JavaScript is required, although some prior programming experience is assumed.

If you are keen to learn TypeScript, this book will give you all the necessary knowledge and skills to tackle any TypeScript project. It will also give you an understanding of which application frameworks are out there, and which one to choose for your next project.

What this book covers

Chapter 1, Up and Running Quickly, shows how to quickly set up a TypeScript development environment, and generate JavaScript. It also includes an introduction to the TypeScript language and its general syntax, and shows how to debug code and use 3rd party JavaScript libraries.

Chapter 2, Exploring the Type System, discusses all of the types used in the TypeScript language, and commonly used language features. It starts with primitive types and type aliases, moves on to object spread and tuples, and finally discusses the use of types in function signatures, callbacks, and overrides.

Chapter 3, Interfaces, Classes, Inheritance, and Modules, builds on the work from the previous chapter, and introduces the object-oriented concepts and capabilities of interfaces, classes, and inheritance. It then shows how to work with modules, which is how we arrange our code, but also how we consume 3rd party libraries.

Chapter 4, Generics and Advanced Type Inference, discusses the more advanced language feature of generics, before working through the concepts of advanced type inference using conditional types, type chaining, and type distribution.

Chapter 5, Asynchronous Language Features, walks the reader through asynchronous programming concepts, starting with callbacks, then on to Promises, and finally async await.

Chapter 6, Decorators, shows the reader how to build and use decorators, which are used within some of the popular Single-Page Application frameworks.

Chapter 7, Integration with JavaScript, takes a look at declaration files, how to find them, how to use them, and how to write them. It also discusses the various compiler options that assist with integrating JavaScript and TypeScript files within the same project.

Chapter 8, Strict Compiler Options, works through each of the strict set of compiler options available with the TypeScript compiler, and explains what errors these options will automatically pick up within our code.

Chapter 9, Using Observables to Transform Data, discusses the RxJS library, and how it uses the Observable pattern to handle streams of events. It discusses how to register for an event stream, how to process data as it flows through the stream, and how to transform this data and create new streams, using combinations of operators.

Chapter 10, Test-Driven Development, explores the Jest unit testing framework, and how to write tests to cover a multitude of test cases. It also discusses asynchronous testing techniques, tests that update the DOM, and how to run end-to-end tests against a running website.

Chapter 11, Angular, discusses the Angular SPA framework, including shared modules, Angular services and form-based input. It builds a website using Angular that combines all of these techniques, along with the Angular Material set of components.

Chapter 12, React, walks through setting up and building a React website using TypeScript and the JSX syntax. It discusses props, event handling, state, and how to use React forms, along with integration of the Material UI library for React.

Chapter 13, Vue, sets up and builds a Vue web-site using TypeScript and class syntax. It walks through Vue components, child components, props, and state, as well as computed properties and form handling, integrating with the Bootstrap Material UI library.

Chapter 14, Node and Express, builds an Express web server with a few lines of code running in Node. It then expands on this to build a functional multi-page Express application, including page redirects, form processing, and session variables.

Chapter 15, An AWS Serverless API, shows how to use Amazon Web Services libraries to build and deploy a full REST-based API using Serverless technologies, backed by a DynamoDB database.

Chapter 16, Micro Front-Ends, discusses the concepts around micro front-ends, and how multiple front-ends can communicate with each other. It then goes on to combine the web sites built within the book using Angular, React, and Vue into a single application using these micro front-end techniques, integrating the REST API built using AWS.

To get the most out of this book

  • You will need the TypeScript compiler and an editor of some sort. The TypeScript compiler is available on Windows, MacOS, and Linux as a Node plugin. Chapter 1, Up and Running Quickly, describes the setup of a development environment
  • This book has been designed in a "type as you read" format. The code snippets are small, so feel free to type out the code yourself, as the text progresses, and learn by building up your code base and knowledge as you go.

Download the example code files

The code bundle for the book is hosted on GitHub at https://github.com/PacktPublishing/Mastering-TypeScript-Fourth-Edition. We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

Download the color images

We also provide a PDF file that has color images of the screenshots/diagrams used in this book. You can download it here: https://static.packt-cdn.com/downloads/9781800564732_ColorImages.pdf.

Conventions used

There are a number of text conventions used throughout this book.

CodeInText: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. For example: "We can configure webpack using the webpack.config.js file."

A block of code is set as follows:

class MyClass {
    add(x: number, y: number) {
      return x + y;
   }
}

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are highlighted:

const modulus: Observable<number> = emitter.pipe(
    map((value: number) => {
        console.log(`received : ${value}`);
        return value % 2;
    }));

Any command-line input or output is written as follows:

npm install @types/express

Bold: Indicates a new term, an important word, or words that you see on the screen, for example, in menus or dialog boxes, also appear in the text like this. For example: "Select Run from the Debug panel."

Warnings or important notes appear like this.

Get in touch

Feedback from our readers is always welcome.

General feedback: Email feedback@packtpub.com, and mention the book's title in the subject of your message. If you have questions about any aspect of this book, please email us at questions@packtpub.com.

Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you have found a mistake in this book we would be grateful if you would report this to us. Please visit, http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details.

Piracy: If you come across any illegal copies of our works in any form on the Internet, we would be grateful if you would provide us with the location address or website name. Please contact us at copyright@packtpub.com with a link to the material.

If you are interested in becoming an author: If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, please visit http://authors.packtpub.com.

Reviews

Please leave a review. Once you have read and used this book, why not leave a review on the site that you purchased it from? Potential readers can then see and use your unbiased opinion to make purchase decisions, we at Packt can understand what you think about our products, and our authors can see your feedback on their book. Thank you!

For more information about Packt, please visit packtpub.com.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Mastering TypeScript - Fourth Edition
Published in: Apr 2021Publisher: PacktISBN-13: 9781800564732
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.
undefined
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 $15.99/month. Cancel anytime

Author (1)

author image
Nathan Rozentals

Nathan Rozentals has been writing commercial software for over 30 years, in C, C++, Java and C#. He picked up TypeScript within a week after its initial release in October 2012 and realized how much TypeScript could help when writing JavaScript. He was one of the first people to start blogging about TypeScript, discussing early frameworks such as Backbone, Marionette, ExtJS and AngularJs. He knew he'd hit the mark when Microsoft staff started to reference his blog posts in their CodePlex discussion forums. Nathan's TypeScript solutions now control User Interfaces in IoT devices, run as stand-alone applications for Point-of-Sale solutions, provide complex application configuration web sites, and are used for mission-critical server APIs.
Read more about Nathan Rozentals