TypeScript Classes and Constructors
Define classes with typed properties and constructors.
TypeScript Classes and Constructors is a free TypeScript Academy lesson on CoddyKit. This is 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, and your progress syncs across the web and the CoddyKit app. The TypeScript Academy course includes 4 lessons in total.
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
Learn TypeScript with an AI tutor — free
Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.
- Courses
- 101
- Lessons
- 352
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. 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. The TypeScript Academy course includes 4 lessons in total.
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, so you can start here or from the beginning and move at your own pace. This is lesson 1 of 4.
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