Chapter 11. Classes
When TypeScript was released for the very first time in 2012, the JavaScript ecosystem and the features of the JavaScript language were not comparable to what we have today. TypeScript introduced many features not only in the form of a type system but also syntax, enriching an already existing language with possibilities to abstract parts of your code across modules, namespaces, and types.
One of these features was classes, a staple in object-oriented programming. TypeScript’s classes originally drew a lot of influence from C#, which is not surprising if you know the people behind both programming languages.1 But they are also designed based on concepts from the abandoned ECMAScript 4 proposals.
Over time, JavaScript gained much of the language features pioneered by TypeScript and others; classes, along with private fields, static blocks, and decorators, are now part of the ECMAScript standard and have been shipped to language runtimes in the browser and the server.
This leaves TypeScript in a sweet spot between the innovation it brought to the language in the early days and standards, which is what the TypeScript team sees as a baseline for all upcoming features of the type system. While the original design is close to what JavaScript ended up with, there are some differences worth mentioning.
In this chapter, we look at how classes behave in TypeScript and JavaScript, the possibilities we have to express ourselves, and the differences between the standard ...
Get TypeScript Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.