thecodex.expert · The Codex Family of Knowledge
Track 1 — Foundations

TypeScript: Foundations

Five lessons from first type annotation to union types, interfaces, and type narrowing.

🕐 ~3 hours5 lessonsTypeScript 5.x

Lessons

Lesson 1

What TypeScript is and how to set it up

TypeScript as a JS superset, tsc compiler, tsconfig basics, and the key principle: types are erased at compile time.

What to look for:

  • TypeScript is a superset — all valid JS is valid TS
  • Types are erased: zero runtime overhead
  • tsc --init to generate tsconfig
  • The Curious tab only for now
🕑 20 min
Lesson 2

Basic types and type annotations

string, number, boolean, null, undefined, any vs unknown, arrays, tuples, and type inference.

What to look for:

  • Type inference — you don't need to annotate everything
  • any vs unknown — prefer unknown, it requires narrowing
  • Union types string | number
  • The literal types section: "north" | "south"
🕑 40 min
Lesson 3

Interfaces and type aliases

interface vs type alias, optional and readonly properties, extending interfaces, and structural typing.

Prerequisite: Lesson 2

What to look for:

  • The interface User example — optional ? and readonly
  • Structural typing — shape matters, not name
  • Discriminated unions — the kind field pattern
  • interface extends vs type &
🕑 40 min
Lesson 4

Union types and type narrowing

Narrowing with typeof, instanceof, in, discriminated unions, user-defined type guards, and never.

Prerequisite: Lesson 3

What to look for:

  • The Exploring tab — narrowing section
  • typeof / instanceof / in — each narrows differently
  • User-defined type guard: value is string return type
  • never — unreachable code branches
🕑 40 min
Lesson 5

Functions with TypeScript

Parameter types, return types, optional parameters, rest params, overloads, and function type signatures.

Prerequisite: Lessons 1-4

What to look for:

  • Function type signatures (param: type): ReturnType
  • Optional parameters — must come after required
  • void vs undefined return type
  • The Formatter interface example — function type in interface
🕑 30 min

How to use this track: Each lesson links to the Codex reference page. Use reading level tabs. Check "What to look for". Come back here for the quiz.

Track quiz

4 questions on the Foundations track.

What happens to TypeScript types at runtime?

What is the difference between any and unknown?

What makes TypeScript "structural" rather than "nominal"?

What does the ? in interface User { age?: number } mean?

Practitioner track →
#128311; TypeScript Snippets

14 copy-ready TypeScript patterns with live Try it buttons.

TS Snippets #8594;