Book Image

TypeScript High Performance

By : Ajinkya Kher
Book Image

TypeScript High Performance

By: Ajinkya Kher

Overview of this book

<p>In a world where a tiny decrease in frames per second impacts customer engagement greatly, writing highly scalable code is more of a necessity than a luxury. Using TypeScript you get type checking during development. This gives you the power to write optimized code quickly. This book is also a solid tool to those who’re curious to understand the impact of performance in production, and it is of the greatest aid to the proactive developers who like to be cognizant of and avoid the classic pitfalls while coding.</p> <p>The book will starts with explaining the efficient implementation of basic data Structures, data types, and flow control. You will then learn efficient use of advanced language constructs and asynchronous programming. Further, you'll learn different configurations available with TSLint to improve code quality and performance. Next, we'll introduce you to the concepts of profiling and then we deep dive into profiling JS with several tools such as firebug, chrome, fiddler. Finally, you'll learn techniques to build and deploy real world large scale TypeScript applications.</p>
Table of Contents (17 chapters)
Title Page
Credits
Foreword
About the Author
Acknowlegement
About the Reviewer
www.PacktPub.com
Customer Feedback
Preface
7
Profile Deployed JS with Developer Tools and Fiddler

Preface

Over the last two decades, JavaScript has grown from enabling developers to perform simple interactions with in-browser HTML to being the core of enterprise applications, both frontend and backend. This success has become more apparent with the advent and creations of NodeJS, Cordova, Ionic, and serverless frameworks, all of which have adopted and support TypeScript. This growth, coupled with the ever-increasing demand for complex and performant JavaScript, has fueled the need for stricter typing, structures, and code decoupling.

TypeScript, created by Microsoft, is the long-awaited solution to these needed language constructs. It is a superset of JavaScript, allowing for compilation to JavaScript and for JavaScript to run within TypeScript. TypeScript is both open source and has backing from major JavaScript libraries and frameworks, namely React, Angular, Express, Knockout, and Ionic. This backing is evidence alone that TypeScript has garnered support from the cutting edge in the industry.

With this evolution, it is necessary for learning to take place for newbies and gurus alike. This book has been designed to walk through various topics of the language, building into meaningful constructs to help you, as a TypeScript developer, build scalable, efficient, and maintainable applications from the first line of code. We start by walking you through language structure and terminology, continue through optimizing your code to load quickly and fine-tune performance, and wrap up with a discussion on building and deploying applications for large-scale and enterprise applications.

TypeScript is here to stay and will be looked back upon as the next iteration of JavaScript just as its predecessors, such as Prototype, jQuery, Dojo, and Mootools, were. This book will walk you through the language and will explain how to write efficient enterprise TypeScript to scale.

What this book covers

This book has been assembled in topics that allow you to focus on your topics of interest. Although we have tried to build self-contained chapters and sections, we highly recommend reading each chapter thoroughly, as the latter sections in the book build on material from the initial chapters.

Part I – Efficient usage of data structures, language constructs, and handling asynchrony

Chapter 1, Efficient Implementation of Basic Data Structures and Algorithms, covers the efficient implementation of basic TypeScript data structures, data types, and flow control with the help of classic algorithms.

Chapter 2, Variable Declarations, Namespaces, and Modules, describes the distinction and correct usage of variable declarations. It also describes code organization strategies, namely leveraging namespaces and modules.

Chapter 3, Efficient Usage of Advanced Language Constructs, covers several different language constructs in TypeScript. It explains how to use them, the scenarios in which to use each construct, and their efficient usage.

Chapter 4,  Asynchronous Programming and Responsive UI, is a deep dive into the world of asynchronous programming. We walk you through the massive performance hits your application can take if not built correctly, and we discuss strategies and tips for efficient coding.

Part II – Performance monitoring, code quality, and resource optimizations

Chapter 5, Writing Quality Code, covers the several configurations available with TSLint and how they can be used to improve code quality and performance.

Chapter 6, Efficient Resource Loading - Critical Rendering Path, introduces the critical rendering path and the steps involved in the process of loading a web application. We discuss strategies for quick and non-blocking resource loading to produce a highly responsive and performant application load.

Chapter 7, Profile Deployed JS with Developer Tools and Fiddler, introduces the concept of profiling and the tools available. We compare the performance results of quality code written with the help of TSLint and compare it to poorly written TypeScript code.

Part III – Building and deploying strategies for large-scale TypeScript projects

Chapter 8, Building and Deploying Strategies for Large Scale Projects, covers the build and deployment process of real-world, enterprise-scale TypeScript applications.

What you need for this book

The book requires the following things:

  • Node and NPM
  • TypeScript
  • Mocha Test Framework
  • Chai Assertion Library
  • Windows, Linux, or MacOS
  •  Modern browsers--Chrome, Edge, and IE
  • Telerik Fiddler
  • Frontend editor--preferably VS Code or Atom/Sublime Text

Who this book is for

The scope of this book is broad, as are the applications and solutions that can be delivered through TypeScript. As such, this book is essential for those who have a passion for software at every stage of the life cycle, from ideation to architecture, design, build, and test. This book should appeal to people who have embraced TypeScript for years and people who have been in the JavaScript world and have debated making the jump to TypeScript.

Basic knowledge of TypeScript and some experience using JavaScript are prerequisites for this book.

Conventions

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: "Since the text variable was not previously defined, the log output will now display a compilation error." A block of code is set as follows:

    // const tests
    function constTest(): () => number {
       const x: number = 16;
       x = 4; // Left-hand side of assignment expression cannot be  
       a constant
       return function innerFunction(): number {
         x++; // the operand of an increment or decrement operator   
         cannot be a constant
         return x;
        }
       }

        console.log('const test: ', constTest()());

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

 [default]
 exten => s,1,Dial(Zap/1|30)
 exten => s,2,Voicemail(u100)
exten => s,102,Voicemail(b100)
 exten => i,1,Voicemail(s0)

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

ts-mocha test.ts

New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: "Let's take a look at the Network tab of the Developer Tools."

Note

Warnings or important notes appear like this.

Note

Tips and tricks appear like this.

Reader feedback

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.

Customer support

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.

Downloading the example code

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:

  1. Log in or register to our website using your e-mail address and password.
  2. Hover the mouse pointer on the SUPPORT tab at the top.
  3. Click on Code Downloads & Errata.
  4. Enter the name of the book in the Search box.
  5. Select the book for which you're looking to download the code files.
  6. Choose from the drop-down menu where you purchased this book from.
  7. 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 https://github.com/PacktPublishing/TypeScript-High-Performance. We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

Errata

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

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.

Questions

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.