TypeScript allows developers to write readable and maintainable web applications. Editors can provide several tools to the developer, based on types and static analysis of the code. In this book, you will learn how you can use TypeScript to build clean web applications. You will learn how to use Angular 2 and React.
You will also learn how you can use TypeScript for servers, mobile apps, command-line tools, and games. We will build various servers, write a mobile app, rewrite Pac Man, and build Tic-Tac-Toe as a command-line application. You will also learn functional programming. This style of programming will improve your general code skills. You will see how this style can be used in TypeScript.
The book can be divided in two sections. The first section, chapters 1 to 4, describe how you can build standard application. These chapters introduce Angular 2 and React for web applications, NodeJS for servers and NativeScript for mobile apps. You should read chapters 1 to 3 in a sequence.
The second section, chapters 5 to 8, introduce more complex concepts. You will learn functional programming in chapters 5 to 7. The last chapter contains guidance to migrate a JavaScript codebase to TypeScript. You can read chapters 5 to 7 when you have not read chapters 1 to 4, though chapter 5 requires some knowledge of React.
Chapter 1, TypeScript 2.0 Fundamentals, will explain core principals to create (web) applications with TypeScript. If you have some basic knowledge of TypeScript 2.0 then you can skim over this chapter or use it as a reference while reading the other chapters. If you have not used TypeScript yet, then this chapter will teach you the fundamentals of TypeScript 2.0
Chapter 2, A Weather Forecast Widget with Angular 2, you will learn how you can build an application in Angular 2. The chapter introduces core principals of Angular and will use an online API as source for the weather forecast.
Chapter 3, Note-Taking App with a Server, we will build a server and client with Node and Angular for this application. You will see how code can be shared between the client and the server.
Chapter 4, Real-Time Chat, introduces React and websockets. Using these techniques, we will write the server and client of the chat application.
Chapter 5, Native QR Scanner App, after having written three web applications, we will now write a mobile app. You will learn how you can use NativeScript and its plugins to write a native app.
Chapter 6, Advanced Programming in TypeScript, covers more advanced features of TypeScript, including type guards, control flow analysis and performance of algorithms.
Chapter 7, Spreadsheet Applications with Functional Programming, introduces a different programming style: functional programming. You will learn how this can be used in TypeScript. We will use React with a Flux-based architecture, which fits nicely with TypeScript and Functional Programming.
Chapter 8, Pac Man in HTML5, will show how to use the HTML5 canvas to create a game. We will use some Functional Programming again, and take a look at how we can create a framework for it based on the Flux architecture.
Chapter 9, Playing Tic-Tac-Toe against an AI, will explain how to build a command-line application in which you can play Tic-Tac-Toe. You will learn how you can learn the computer to play the game. When done correctly, the computer should never lose.
Chapter 10, Migrate JavaScript to TypeScript, will show how you can incrementally migrate a JavaScript codebase to TypeScript. We will focus on how you can keep the project working during this transition.
You will need an editor to write the code, a terminal to compile the code, and a browser to see the results. Visual Studio Code and Atom with atom-typescript are good editors in which you can write TypeScript code. These are available for Windows, Mac, and Linux. You have to compile TypeScript in a terminal. On Windows, you can use the Command Prompt or Powershell for that. On a Mac, you can use Terminal.
To compile TypeScript, you need NodeJS. You can find details on how you can install it in the first chapter.
Chapter 5, Native QR Scanner App, has more requirements to run the mobile app in an emulator or a device. Details about how you can install these dependencies are found in the chapter.
If you are interested in building fun projects using TypeScript, then this book is for you. This book will appeal to web developers who wish to make the most of TypeScript. You should be familiar with the fundamentals of JavaScript.
In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.
Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "We can include other contexts through the use of the include
directive."
A block of code is set as follows:
export function factorial(x: number): number { if (x <= 1) return 1; return x * factorial(x - 1); }
When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:
export function factorial(x: number): number {
if (x <= 1) return 1;
return x * factorial(x - 1);
}
Any command-line input or output is written as follows:
npm init -y
New terms and important words are shown in bold.
Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.
To send us general feedback, simply e-mail [email protected], and mention the book's title in the subject of your message.
If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.
Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.
You can download the example code files for this book from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.
You can download the code files by following these steps:
Log in or register to our website using your e-mail address and password.
Hover the mouse pointer on the SUPPORT tab at the top.
Click on Code Downloads & Errata.
Enter the name of the book in the Search box.
Select the book for which you're looking to download the code files.
Choose from the drop-down menu where you purchased this book from.
Click on Code Download.
Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:
WinRAR / 7-Zip for Windows
Zipeg / iZip / UnRarX for Mac
7-Zip / PeaZip for Linux
The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/TypeScript-Blueprints. We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!
We also provide you with a PDF file that has color images of the screenshots/diagrams used in this book. The color images will help you better understand the changes in the output. You can download this file from http://www.packtpub.com/sites/default/files/downloads/TypeScriptBlueprints_ColorImages.pdf.
Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books-maybe a mistake in the text or the code-we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.
To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.
Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.
Please contact us at [email protected] with a link to the suspected pirated material.
We appreciate your help in protecting our authors and our ability to bring you valuable content.
If you have a problem with any aspect of this book, you can contact us at [email protected], and we will do our best to address the problem.