O'Reilly logo

Mastering TypeScript by Nathan Rozentals

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Classes

A class is a definition of an object, what data it holds, and what operations it can perform. Classes and interfaces form a cornerstone of the principles of object-oriented programming, and often work together in design patterns. A design pattern is a simple programming structure that has been proven to be the best way of tackling a specific programming task. More on design patterns later.

Let's recreate our previous code sample using classes:

interface IComplexType { id: number; name: string; print(): string; } class ComplexType implements IComplexType { id: number; name: string; print(): string { return "id:" + this.id + " name:" + this.name; } } var complexType: ComplexType = new ComplexType(); complexType.id = 1; complexType.name = "complexType"; ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required