ReviseAlgo Logo

Classes in TypeScript

Class Basics — Properties & Methods

Learn how TypeScript enhances JavaScript ES6 classes with static type checking for fields, methods, and constructors.

Last Updated: July 29, 2026 10 min read

TypeScript classes provide full object-oriented programming (OOP) capabilities with static type annotations for field properties, constructor arguments, and instance methods.

1. Introduction & Architecture

2. Deep Dive & Core Concepts

In TypeScript, class fields must be declared before they can be assigned in the constructor unless parameter properties are used.

3. Basic Code Example

4. Advanced Production Patterns

5. Interactive Code Playground

class Person {
  name: string;
  constructor(name: string) { this.name = name; }
  speak() { console.log(`Hi, I'm ${this.name}`); }
}
new Person("Bob").speak();

6. Common Pitfalls & Edge Cases

Warning: Under strictPropertyInitialization, all uninitialized class properties must be assigned in the constructor or marked with an optional or non-null assertion.

7. Interview Q&A & Quizzes

Q: What is strictPropertyInitialization in tsconfig?

A: A compiler flag ensuring class properties are initialized in the constructor or assigned default values.

8. Summary Comparison Table

FeatureJavaScript ES6TypeScript
Field DeclarationsOptionalRequired with Types
| Method Return Types | Dynamic | Statically Checked |