TypeScript Classes and Constructors
Define classes with typed properties and constructors.
TypeScript Classes and Constructors is a free TypeScript Academy lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the TypeScript Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Welcome
Class Declaration with Properties
class Person {
name: string;
age: number;
constructor(name: string, age: number) {
this.name = name;
this.age = age;
}
}Parameter Properties Shorthand
class Person {
constructor(
public name: string,
private age: number
) {} // properties created automatically
}Typed Methods
class Calculator {
add(a: number, b: number): number {
return a + b;
}
}Getters and Setters
class Circle {
constructor(private radius: number) {}
get area(): number { return Math.PI * this.radius ** 2; }
set r(v: number) { this.radius = v; }
}Class as a Type
class Dog { name = 'Rex'; bark() { return 'Woof'; } }
const d: Dog = new Dog();Static Members
class MathHelper {
static PI = 3.14159;
static square(n: number): number { return n * n; }
}
console.log(MathHelper.PI);Class Inheritance
class Animal {
constructor(public name: string) {}
speak(): string { return '...'; }
}
class Dog extends Animal {
speak(): string { return 'Woof!'; }
}Abstract Classes
abstract class Shape {
abstract area(): number;
describe(): string { return `Area: ${this.area()}`; }
}
class Square extends Shape {
constructor(private side: number) { super(); }
area() { return this.side ** 2; }
}this Type in Classes
class Builder {
private parts: string[] = [];
add(p: string): this { this.parts.push(p); return this; }
build(): string { return this.parts.join(','); }
}Class vs Interface vs Type
Quick Check
Recap
Frequently asked questions
Is the “TypeScript Classes and Constructors” lesson free?
Yes — the full text of “TypeScript Classes and Constructors” is free to read here on the web, and the TypeScript Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the TypeScript Academy course, upgrade to CoddyKit PRO.
What will I learn in “TypeScript Classes and Constructors”?
Define classes with typed properties and constructors. You practise TypeScript Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start TypeScript Academy?
No prior experience is required. TypeScript Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “TypeScript Classes and Constructors” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this TypeScript Academy lesson?
Yes. Every TypeScript Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- TypeScript Classes and Constructors
- public, private, and protected Modifiers
- readonly Properties and Parameter Properties
- Implementing Interfaces with Classes