TypeScript, by example
TypeScript through annotated examples - the type system made practical.
30 lessons · Updated 2026-07-08
- 01Hello, WorldRunning TypeScript with tsx and compiling with tsc - the two modes every TypeScript project uses.
- 20Basic TypesTypeScript's scalar vocabulary: string, number, boolean, null, undefined, symbol, bigint, any, and unknown.
- 30The never TypeUsing never for unreachable code, exhaustive switches, and filtering impossible union branches.
- 35Filtering Unions with neverReturning never from a conditional type to remove members from a union.
- 40Type InferenceHow TypeScript infers types from assignments: const vs let widening, as const, and function return types.
- 50InterfacesDeclaring object shapes with required, optional, readonly, and extended interface fields.
- 60Type AliasesNaming primitive, object, union, and intersection shapes with the type keyword.
- 70Advanced Type AliasesGeneric, recursive, and template literal type aliases for reusable type-level shapes.
- 80Union TypesUnion, intersection, and literal unions, the building blocks for TypeScript variant modeling.
- 90Discriminated UnionsModeling object variants with one shared literal field that TypeScript can narrow.
- 100Designing Tagged ShapesWhy loose object shapes do not narrow, and how to parse unknown JSON into strict tagged unions.
- 110GenericsType parameters for functions, interfaces, and classes that preserve the caller's exact type.
- 120Generic ConstraintsConstraining type parameters with extends and adding default type parameters for ergonomic APIs.
- 130FunctionsTyped function parameters, return annotations, optional parameters, defaults, and rest parameters.
- 140Function Types and OverloadsTyping callbacks, higher-order functions, stored function references, and overload signatures.
- 150ClassesConstructor parameter shorthand, access modifiers, readonly fields, and abstract classes.
- 160Class ContractsHaving classes implement interfaces and checking that required methods are present.
- 170Private FieldsThe difference between TypeScript private fields and ECMAScript
- 180EnumsNumeric and string enums, reverse mapping, runtime emit, and why string values are safer.
- 190Const Enums and AlternativesConst enum inlining, package-boundary hazards, and string literal unions as the usual alternative.
- 200Mapped TypesBuilding new object types by transforming every key of an existing type.
- 210Key RemappingRenaming and filtering keys inside mapped types with as, template literals, and never.
- 220Utility TypesBuilt-in helpers like Partial, Required, Readonly, Record, Pick, Omit, Exclude, and Extract.
- 230Function Utility TypesDeriving function, constructor, and async payload types with ReturnType, Parameters, InstanceType, and Awaited.
- 240NarrowingControl-flow analysis with typeof, instanceof, in, equality, truthiness, and assignment narrowing.
- 250Type Guards and AssertionsUser-defined type guards, runtime validation for unknown data, assertion functions, and exhaustive never checks.
- 260ModulesES module import/export in TypeScript, import type, and barrel re-exports.
- 270Module ResolutionmoduleResolution, path aliases, node16/nodenext imports, and isolatedModules for single-file transpilers.
- 280Declaration FilesWriting .d.ts files for untyped JavaScript modules, globals, @types packages, and augmentation.
- 290Generated DeclarationsEmitting .d.ts files from TypeScript and generating client types from OpenAPI or GraphQL schemas.
Enjoyed this? Get more software craft delivered to your inbox.