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. 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 id property has been defined as type number. The print function simply logs a message to the console. Note that all we have done here is to define what data this class can hold, and what it can do. If we attempt to compile this code, however, we will generate an error, as follows:
error TS2564: Property 'id' has no initializer and is not definitely...