A comprehensive guide to learning Object-Oriented Programming (OOP) in TypeScript, complete with detailed notes and hands-on exercises.
This repository contains everything you need to master TypeScript OOP concepts:
All documentation is organized in the docs/ folder:
- Real-World Use Cases - Understanding when and why to use classes
- Classes and Objects - Comprehensive guide covering classes, objects, properties, constructors, methods, and the
thiskeyword - Static Members - Class-level properties and methods
- Inheritance - Extending classes,
superkeyword, and method overriding - Getters and Setters - Property accessors, validation, and computed properties
- Access Modifiers & Encapsulation - public, private, protected, and readonly
- Abstract Classes - Abstraction, abstract methods, and templates
- Interfaces & Polymorphism - Contracts, multiple implementations, and polymorphism
Quick Reference:
- Keywords Reference - Complete reference for all OOP keywords (class, new, this, static, extends, super, etc.)
Progressive exercises organized by lesson:
- Lesson 01: Classes, Objects, Properties, Constructors, Methods, and
this- 7 exercises (Easy β Hard) - Lesson 02: Static Members - 5 exercises (Easy β Hard)
- Lesson 03: Inheritance - 5 exercises (Easy β Hard)
- Lesson 04: Getters and Setters - 5 exercises (Easy β Hard)
- Lesson 05: Access Modifiers and Encapsulation - 5 exercises (Easy β Hard)
- Lesson 06: Abstract Classes - 5 exercises (Easy β Hard)
- Lesson 07: Interfaces and Polymorphism - 5 exercises (Easy β Hard)
- Node.js (v14 or higher)
- TypeScript (v4 or higher)
- A code editor (VS Code recommended)
-
Fork this repository on GitHub (click the "Fork" button at the top right)
-
Clone YOUR fork to your local machine:
git clone https://github.com/YOUR-USERNAME/typescript-oop-guide.git
cd typescript-oop-guide- Set up the upstream remote (this is how you'll get updates):
git remote add upstream https://github.com/ah-materials/typescript-oop-guide.git
git remote -v # Verify it's set up correctly- Install dependencies:
npm installSee CONTRIBUTING.md for detailed instructions.
-
Read the notes in order:
- Start with
docs/00-real-world-use-cases.md - Then read
docs/01-classes-and-objects.md- this comprehensive guide covers classes, objects, properties, constructors, methods, andthis - Progress through the remaining topics (02-07)
- Take your time to understand each concept
- Use the Keywords Reference for quick lookups
- Start with
-
Complete the exercises:
- Each lesson has its own folder in
exercises/(e.g.,exercises/lesson-01/) - Lesson 01 contains 7 exercises covering all foundational concepts; other lessons contain 5 exercises each
- Exercises have progressive difficulty (Easy β Medium β Hard)
- Read the
README.mdin each lesson folder for exercise descriptions - Complete exercises in order within each lesson
- Run your solutions with:
npx ts-node exercises/lesson-<number>/<file-name>.ts - Commit your solutions to your forked repository to track your progress
- Each lesson has its own folder in
-
Practice and experiment:
- Modify the examples from the notes
- Try creating your own classes
- Combine concepts in creative ways
Finding exercises:
Each lesson has its own directory:
exercises/
βββ lesson-01/ # Classes, Objects, Properties, Constructors, Methods, and `this`
β βββ README.md # Exercise descriptions and requirements
β βββ 01-simple-class-easy.ts
β βββ 02-class-with-methods-easy.ts
β βββ 03-multiple-objects-medium.ts
β βββ 04-object-interactions-medium.ts
β βββ 05-library-system-hard.ts
β βββ 06-parameter-properties-medium.ts
β βββ 07-this-context-problem-medium.ts
βββ lesson-02/ # Static Members
βββ lesson-03/ # Inheritance
βββ lesson-04/ # Getters and Setters
βββ lesson-05/ # Access Modifiers and Encapsulation
βββ ... (lesson-06 through lesson-07)
Completing exercises:
- Navigate to the lesson folder (e.g.,
exercises/lesson-01/) - Read the
README.mdfor exercise requirements - Edit the exercise TypeScript files (they start as empty templates)
- Run your solution:
npx ts-node exercises/lesson-01/01-simple-class-easy.ts - Test thoroughly and move to the next exercise
Running exercise files:
# Run exercises from any lesson
npx ts-node exercises/lesson-01/01-simple-class-easy.ts
npx ts-node exercises/lesson-01/08-parameter-properties-medium.ts
npx ts-node exercises/lesson-09/05-complete-application-hard.tsSaving your work:
- Commit your exercise solutions in your forked repository to track your learning progress
- Your solutions are personal - don't create PRs to submit exercise solutions
- Focus on learning at your own pace!
IMPORTANT: This repository is regularly updated with new exercises, bug fixes, and improvements. Check for updates weekly!
Every week (or before starting a new lesson), run these commands to pull the latest changes:
# 1. Check what's new in the original repository
git fetch upstream
# 2. Make sure you're on your main branch
git checkout main
# 3. Merge the updates from the original repo into your fork
git merge upstream/main
# 4. Push the updates to your fork on GitHub
git push origin mainWhat this does:
git fetch upstream- Downloads the latest changes from the original repositorygit merge upstream/main- Combines those changes with your work (your exercise solutions stay intact!)git push origin main- Updates your fork on GitHub
Tip: Always commit your work before updating to avoid losing your progress!
Work directly on your main branch to keep things simple:
-
Complete exercises and commit regularly:
git add . git commit -m "Complete lesson 3 exercises" git push origin main
-
When you need updates, follow the steps in "How to Get New Updates" above
Why work on main? Working directly on main keeps your workflow simple and prevents GitHub from showing the "Compare & pull request" button that appears when you push feature branches. This helps avoid confusion since learners should NOT create pull requests for their exercise solutions.
The documentation is structured to build progressively:
Basics (Understanding the Foundation)
βββ 00: Why use classes?
βββ 01: Comprehensive guide - classes, objects, properties, constructors, methods, and `this`
β
Class-Level Features
βββ 02: Static members (class-level vs instance-level)
β
Code Reuse Through Inheritance
βββ 03: Inheritance (code reuse through extension, subclasses)
β
Advanced Property Access
βββ 04: Getters and setters (controlled access patterns)
βββ 05: Access control (public, private, protected, readonly)
β
Advanced Concepts (Abstraction and Contracts)
βββ 06: Abstract classes (templates for subclasses)
βββ 07: Interfaces & polymorphism (contracts and flexibility)
π¨βπ If you're just completing exercises: DO NOT create Pull Requests! Just commit your solutions to your fork and use git fetch upstream + git merge upstream/main to get updates. See the Keeping Your Fork Updated section above.
π οΈ If you want to contribute improvements to the learning materials: We welcome contributions! See below.
Contributions to improve the learning materials are welcome:
- Additional exercises with clear requirements and examples
- Improvements to existing notes (clarity, examples, corrections)
- Advanced topics (generics, decorators, mixins, design patterns)
- Code examples demonstrating real-world use cases
- Bug fixes or typo corrections
- Fork this repository
- Clone your fork and set up the upstream remote
- Create a new branch (
git checkout -b your-name/feature-description) - Make your changes to the learning materials
- Test thoroughly
- Commit and push to your fork
- Open a Pull Request describing your improvements
For detailed contribution instructions, including how to set up your development environment and guidelines for different types of contributions, see CONTRIBUTING.md.
Solutions are intentionally not included to encourage independent learning. If you're stuck:
- Review the relevant note file in the
docs/folder - Check the Keywords Reference
- Check TypeScript documentation
- Experiment with different approaches
- Ask for help in the discussions section
This project is open source and available under the MIT License.
Created as a comprehensive learning resource for developers learning TypeScript OOP concepts.
Happy Learning! π
If you find this guide helpful, please consider giving it a star β