Module 18 Web Engineering

TypeScript & JavaScript Mastery

JavaScript is one of the most widely misunderstood languages in professional use. Its coercion rules, prototype model, and event loop are so often cargo-culted or avoided that entire generations of developers work in it daily without understanding it. TypeScript layers type safety on top — but adds its own complexity with generics, conditional types, and mapped types that most developers generate with AI rather than write themselves. This module fixes that. You'll go deep on JavaScript's execution model: V8's call stack, libuv's event loop, the difference between the task queue and the microtask queue. You'll understand closures at the implementation level — how variables are captured, where the classic loop bug comes from, how to avoid it. You'll understand the prototype chain and `this` binding deeply enough to explain all four binding rules without looking them up. On the TypeScript side, you'll master the type system features that make TypeScript powerful rather than just verbose: generic constraints, conditional types, mapped types, discriminated unions, and the `infer` keyword. By the end of this module, you'll be writing TypeScript that genuinely improves correctness and catches bugs at compile time — not TypeScript that just adds type annotations to JavaScript.

What You'll Learn

  • 1
    JavaScript Quirks and the Language Model — Coercion, truthiness, typeof
  • 2
    The Event Loop Deep Dive — V8 call stack, libuv, task vs microtask queue
  • 3
    Closures and Scope Chains in Practice — Capture by reference, loop bugs, patterns
  • 4
    The Prototype Chain and `this` Binding — Four rules, arrow functions, class syntax
  • 5
    TypeScript Type System Deep Dive — Generics, conditional types, mapped types, discriminated unions
  • 6
    Node.js Internals — libuv phases, streams, Buffers, worker threads
  • 7
    Module Systems — CommonJS vs ESM, dynamic imports, tree shaking
  • 8
    Build Tools and Package Management — Bundlers, Vite, esbuild, monorepos

Capstone Project: Build a TypeScript Utility Library Published to npm with Full Type Safety

Build and publish a TypeScript utility library to npm with zero dependencies — implementing a set of typed utility functions (deep merge, type-safe pick/omit, async retry, result types) with conditional types, mapped types, and generics that make invalid usage a compile error rather than a runtime bug. The library must have full TypeScript declarations, JSDoc, tests, and a build pipeline that produces both CommonJS and ESM output.

Why This Matters for Your Career

JavaScript's quirks are the source of a class of bugs that appear regularly in production codebases — coercion surprises, stale closures in async code, this binding in event handlers, microtask ordering in Promise chains. Engineers who understand the language model can spot and fix these bugs in minutes. Those who don't will encounter them repeatedly and never quite understand what went wrong. TypeScript's type system is one of the most powerful in any mainstream language, but most developers use only 10% of it — basic types, interfaces, and maybe some generics. The conditional type, mapped type, and discriminated union features that make TypeScript genuinely safer are routinely left on the table. Engineers who use the full type system write libraries and APIs that are safer by construction — invalid inputs that would cause runtime errors instead become compile errors. Node.js internals matter for server-side performance. Understanding libuv's event loop phases, why CPU-bound work blocks the event loop, when to use worker threads, and how streams work for large file processing — these are the decisions that affect server throughput under real load. The engineers who understand Node.js internals are the ones who can diagnose production performance issues and fix them at the right level.