Skip to main content
D
TypeScript
TypeScript Classes

TypeScript Classes

TypeScript adds strict types to Object-Oriented classes.

Read Time
5 min read
Difficulty
Beginner
Last Updated
Jun 15, 2026
Version
v1.0.0

Introduction

JavaScript uses classes to create blueprints for complex objects, like a Player or an Enemy in a game. TypeScript forces developers to declare every property and its type before the class even starts building the object.

Example

Example
1/* this creates a typed class */
2class Player {
3  name: string;
4  score: number;
5
6  constructor(playerName: string) {
7    this.name = playerName;
8    this.score = 0;
9  }
10}

Key Points

  • You must declare all properties at the top of the class.
  • The `constructor` initializes the actual data.
  • Methods inside the class also require strict types.
  • It prevents missing properties when creating new objects.

Up Next

Continue your journey with the next topic.

Go to TS Access Modifiers