Now, let's dive into how you can implement classes in TypeScript.
TypeScript classes
Basics
Creating a class in TypeScript is really straightforward:
class Car { }
As we have mentioned before, classes were only officially introduced in the JavaScript ecosystem with ES2015. Luckily for us, TypeScript can down-level emit classes if you target ES5 or earlier versions; thus, it allows you to use classes in your TypeScript code even if you are targeting older versions of the specification. This is great for maintaining compatibility while still being able to use new features.
The preceding example gets translated to the following ES5 code:
"use strict";
var Car = /** @class */ (function () {
function Car() {...