Classes
A class bundles data and actions together.
Like a toy with buttons and a name tag on it.
TypeScript adds types to fields, constructors, and methods.
It also adds helpers like parameter properties and implements.
Fields, constructor, methods
A field is a piece of data on each instance.
An instance is one toy made from the class.
The constructor fills fields when you make a new instance.
A method is an action the toy can do.
Parameter properties
Put public, private, or readonly in front of a constructor parameter.
That both declares and assigns the field in one step.
Less repeating. Same result.
implements an interface
A class can promise to match an interface.
An interface is a form with required blanks.
TypeScript errors if a required method or property is missing.
Inheritance with extends
Inheritance means a child class starts from a parent class.
Subclasses inherit members and can override methods.
Override means replace a method with a new version.
Call super() before using this in a child constructor.
this stays typed
Inside methods, this is typed as the class.
Your editor knows which fields and methods exist.
That stops many typos early.
TypeScript classes are JavaScript classes plus checked fields and safer inheritance.
Test yourself
Three quick questions made just for this lesson. Earn 10 XP per correct answer.