Book Image

TypeScript 3.0 Quick Start Guide

By : Patrick Desjardins
Book Image

TypeScript 3.0 Quick Start Guide

By: Patrick Desjardins

Overview of this book

<p>TypeScript is designed for the development of large applications and can be used to develop JavaScript applications for both client-side and server-side execution. This book is the ideal introduction to TypeScript, covering both the basics and the techniques you need to build your own applications.</p> <p>We start by setting up the environment and learning about the build tools that support TypeScript. Then we look at scoping of a variable, and the difference between a undefined variable and a null variable. You will then see the difference between an object, an Object, an object literal, and an object built with a constructor, crucial concepts in understanding TypeScript.</p> <p>You will learn how to make your code more generic to increase the reusability of your classes, functions, and structures, and to reduce the burden of duplicating code. We look at creating definition files to transform the actual JavaScript code to be compatible with TypeScript.</p> <p>By the end of the book, you will have worked with everything you need to develop stunning applications using TypeScript.</p>
Table of Contents (14 chapters)
Title Page
Copyright and Credits
Packt Upsell
Contributors
Preface
Free Chapter
1
Getting Started with TypeScript
Index

Bringing abstraction with an abstract class


Abstraction is an object-oriented concept that allows us to have a base class that delegates the implementation of a function to the class that extends the abstract class.

 

 

The following example creates the main class by instantiating the custom logic class. It invokes the main function, which will execute the abstract function. To the MainClass class, the abstract function is a black box. It only knows its name, parameter types, and returns types. The example executes the commented block code A-C-B in that particular order:

abstract class MainClass {
 public mainCoreLogic(): void {
   // Code here [A]
   this.delegatedLogic();
   // Code here [B]
 }

 public abstract delegatedLogic(): void;

}


class CustomLogic extends MainClass {

 public delegatedLogic(): void {
   // Do some custom logic here [C]
 }

}

const c: MainClass = new CustomLogic();
c.mainCoreLogic();

The abstract is powerful when you pass a computed value to the abstract class and...