Skip to content

DanDo385/typescript-edu

Repository files navigation

🔷 TypeScript 10x Mini-Projects

Learn TypeScript's type system through 10 progressively challenging projects with extreme documentation

TypeScript License: MIT PRs Welcome

🎯 What You'll Master

This isn't just another TypeScript tutorial. This repository teaches you:

  • TypeScript's Type System: The real superpower that sets it apart from JavaScript
  • Production Patterns: Type-safe patterns used by top companies (Microsoft, Google, Airbnb)
  • Real-World Applications: Type-safe React, Express, Node.js, and GraphQL
  • Critical Thinking: When TypeScript wins vs when it's overkill
  • Performance Analysis: Understand compile-time, runtime, and bundle size implications
  • Multi-Language Perspective: How TypeScript compares to Python, Rust, and Go

🤔 Why This Repository Exists

The Problem: Most TypeScript tutorials teach syntax, not understanding.

The Solution: This repository provides:

  • 1000+ lines of documentation per project explaining WHY, not just WHAT
  • Honest performance comparisons with other languages
  • Real-world context for every concept
  • Common mistakes and how to avoid them
  • Multi-language comparisons (TypeScript vs Python vs Rust vs Go)
  • Production-ready patterns you'll actually use

📚 Philosophy

TypeScript Isn't Just "JavaScript with Types"

TypeScript is a compile-time type checker for JavaScript that:

  • ❌ Adds zero runtime overhead (types are erased during compilation)
  • ✅ Catches bugs before your code runs
  • ✅ Provides amazing IDE support (autocomplete, refactoring)
  • ✅ Makes large codebases maintainable
  • ✅ Enables fearless refactoring

But it's not perfect:

  • ❌ Adds build complexity
  • ❌ Has a learning curve
  • ❌ Can slow down rapid prototyping
  • ❌ Type definitions can be verbose

This repository teaches you when to use TypeScript and when to skip it.

Our Teaching Approach

  1. Honest: We don't oversell TypeScript. We acknowledge trade-offs.
  2. Practical: Real-world examples, not toy problems.
  3. Thorough: We explain EVERY concept, EVERY symbol.
  4. Comparative: We show how Python, Rust, and Go solve the same problems.
  5. Accessible: We assume you know programming, but not TypeScript.

🗺️ Learning Path

Foundation Projects (1-6): Type System Mastery

Project Focus Key Concepts Difficulty
01 Type System Fundamentals Primitives, unions, intersections, type inference ⭐ Beginner
02 Advanced Types Mapped types, conditional types, utility types ⭐⭐ Intermediate
03 Generics & Constraints Generic functions, constraints, variance ⭐⭐ Intermediate
04 Decorators & Metadata Meta-programming, reflection ⭐⭐⭐ Advanced
05 Async Patterns Promises, async/await, error handling ⭐⭐ Intermediate
06 Type Guards & Narrowing Runtime type safety, discriminated unions ⭐⭐ Intermediate

Real-World Projects (7-10): Production Patterns

Project Focus Technologies Difficulty
07 Express API 🌐 Type-safe backend, middleware, validation ⭐⭐⭐ Advanced
08 React + TypeScript ⚛️ Component typing, hooks, generics ⭐⭐⭐ Advanced
09 Node.js Automation 🤖 CLI tools, file operations, build scripts ⭐⭐ Intermediate
10 GraphQL + TypeScript 📊 Schema types, resolvers, code generation ⭐⭐⭐⭐ Expert

🚀 Quick Start

Prerequisites

  • Node.js 18+ (with npm)
  • Basic programming knowledge (any language)
  • Text editor (VSCode recommended for TypeScript)

Installation

# Clone the repository
git clone https://github.com/yourusername/typescript-10x-mini-projects.git
cd typescript-10x-mini-projects

# Install dependencies
npm install

# Run tests (verify everything works)
npm test

# Start with Project 01
cd 01-type-system-fundamentals

How to Use This Repository

Each project follows the same structure:

01-project-name/
├── README.md          # Learning objectives, prerequisites, concepts
├── lib.ts             # YOUR workspace (TODO stubs to fill in)
├── main.ts            # Interactive demo (run with ts-node)
├── solution.ts        # DETAILED solution (1000+ lines of docs)
└── solution.test.ts   # Comprehensive test suite

Recommended Learning Flow:

  1. Read README.md to understand the concepts
  2. Try to implement lib.ts yourself first
  3. Run main.ts to see the concept in action
  4. Study solution.ts for deep understanding
  5. Run tests with npm test to verify correctness
  6. Experiment by modifying the code

📖 Project Details

Project 01: Type System Fundamentals ⭐

What You'll Learn:

  • How TypeScript's type inference works
  • When to use type annotations vs inference
  • Union types, intersection types, literal types
  • Type aliases vs interfaces
  • The honest truth about any vs unknown

Why It Matters: Understanding TypeScript's type system is the foundation for everything else. You'll learn how compile-time type checking prevents runtime bugs.

Comparison Highlight:

// TypeScript: Compile-time safety
function add(a: number, b: number): number {
    return a + b;
}
add("5", 3); // ❌ Compile error!

// Python: Runtime flexibility (and runtime errors)
def add(a, b):
    return a + b
add("5", 3)  #  Returns "53" (string concatenation)

Project 02: Advanced Types ⭐⭐

What You'll Learn:

  • Mapped types for transforming object shapes
  • Conditional types for type-level logic
  • Template literal types for string manipulation
  • Built-in utility types (Partial, Readonly, Pick, etc.)
  • The infer keyword for type extraction

Why It Matters: Advanced types let you write incredibly flexible, type-safe APIs. This is TypeScript's superpower that no runtime validation library can match.

Real-World Use Case:

// Transform all properties to optional (form state management)
type PartialUser = Partial<User>;

// Make all properties readonly (immutable state)
type ReadonlyUser = Readonly<User>;

// Extract only specific properties (API responses)
type UserPreview = Pick<User, 'id' | 'name' | 'avatar'>;

Project 03: Generics & Constraints ⭐⭐

What You'll Learn:

  • Writing reusable type-safe functions and classes
  • Constraining generic types with extends
  • Multiple type parameters
  • Default type parameters
  • Variance (covariance vs contravariance)

Why It Matters: Generics enable you to write DRY (Don't Repeat Yourself) code that's still type-safe. This is crucial for building libraries and reusable components.

Project 04: Decorators & Metadata ⭐⭐⭐

What You'll Learn:

  • Class, method, property, and parameter decorators
  • Decorator factories and composition
  • Metadata reflection API
  • How frameworks like NestJS and TypeORM work

Why It Matters: Decorators power many popular TypeScript frameworks. Understanding them unlocks framework development and advanced meta-programming.

Project 05: Async Patterns ⭐⭐

What You'll Learn:

  • Properly typing Promises and async functions
  • Error handling patterns in async code
  • Promise combinators (Promise.all, Promise.race)
  • AsyncIterators and generators
  • Comparing callbacks, Promises, and Observables

Why It Matters: Modern JavaScript is async-first. TypeScript's async typing prevents common mistakes like unhandled promise rejections.

Project 06: Type Guards & Narrowing ⭐⭐

What You'll Learn:

  • Built-in type guards (typeof, instanceof)
  • Custom type guards with is predicates
  • Discriminated unions for robust state management
  • Control flow analysis
  • The never type for exhaustiveness checking

Why It Matters: Type guards bridge the gap between TypeScript's static types and JavaScript's dynamic runtime. Essential for working with external data.

Project 07: Express API 🌐 ⭐⭐⭐

What You'll Build: A fully type-safe REST API with validation, error handling, and OpenAPI documentation.

Technologies: Express, Zod (validation), TypeScript

Why It Matters: Backend APIs are where type safety prevents bugs at scale. Learn patterns used in production.

Project 08: React + TypeScript ⚛️ ⭐⭐⭐

What You'll Build: Type-safe React components with hooks, context, and generic patterns.

Technologies: React, TypeScript

Why It Matters: React + TypeScript is the industry standard for large frontend applications.

Project 09: Node.js Automation 🤖 ⭐⭐

What You'll Build: CLI tools and build scripts with type-safe file operations.

Technologies: Node.js, Commander (CLI), fs/promises

Why It Matters: DevOps scripts benefit hugely from type safety. Learn to build reliable automation.

Project 10: GraphQL + TypeScript 📊 ⭐⭐⭐⭐

What You'll Build: A GraphQL API with code generation for end-to-end type safety.

Technologies: GraphQL, Type-GraphQL, GraphQL Code Generator

Why It Matters: GraphQL + TypeScript = the ultimate type-safe API layer. See how schema and types stay in sync.

🎓 What Makes This Repository Different

1. Extreme Documentation

Every solution.ts file contains 1000+ lines with:

  • Module-level docstrings explaining concepts
  • Line-by-line inline comments
  • Performance analysis
  • Memory implications
  • Multi-language comparisons
  • Common mistakes and how to avoid them

2. Honest Comparisons

We compare TypeScript to:

  • Python: For developer experience and flexibility
  • Rust: For type system rigor and performance
  • Go: For simplicity and deployment
  • JavaScript: For runtime behavior

We're honest about when TypeScript is the right choice and when it's not.

3. Real-World Context

Every concept includes:

  • Where you'll use this in production
  • Performance implications (compile-time, runtime, bundle size)
  • When to use this pattern vs alternatives
  • Common pitfalls

4. Production-Ready Code

All code follows:

  • TypeScript best practices
  • Strict mode enabled
  • Comprehensive error handling
  • Extensive test coverage
  • Clear documentation

📊 Repository Statistics

  • Total Lines of Code: 15,000+
  • Documentation Lines: 10,000+
  • Test Cases: 200+
  • Projects: 10
  • Real-World Projects: 4

🤝 Contributing

Contributions are welcome! Please see CONTRIBUTING.md for guidelines.

📜 License

This project is licensed under the MIT License - see the LICENSE file for details.

🙏 Acknowledgments

Inspired by the philosophy of extreme documentation and practical learning. Built to help developers truly understand TypeScript, not just memorize syntax.

📞 Support

🗺️ Next Steps

  1. Start with Project 01: cd 01-type-system-fundamentals
  2. Read the README: Understand the concepts before coding
  3. Try it yourself: Fill in lib.ts before looking at solutions
  4. Study deeply: Read every comment in solution.ts
  5. Run tests: Verify your understanding
  6. Progress sequentially: Each project builds on previous ones

Ready to master TypeScript? Start with Project 01: Type System Fundamentals!

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Used by

Contributors

Languages