A class is a definition of an object, what data it holds, and what operations it can perform. Classes and interfaces form the cornerstone of the principles of object-oriented programming, and often work together in design patterns. A design pattern is a way of using classes and interfaces in a certain way to help tackle common programming problems. More on design patterns later.

Let's take a look at a simple class definition:

    class SimpleClass { 
      id: number; 
      print() : void { 
        console.log(`SimpleClass.print() called`); 

Here, we have used the class keyword to define a class named SimpleClass, and we have defined this class to have a property named id, and a print function. The print function simply logs a message to the console. We can ...

Get Mastering TypeScript - Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.