TypeScript generics: reusable, type-safe functions and components

13 steps · about 3 h 59 min · Intermediate

  1. TypeScript: Documentation - TypeScript for JavaScript Programmers (doc, typescriptlang.org, 10 min)

    Start with the official short intro, where generics first appear as variables for types, as in Array<string>.

  2. TypeScript Generics Explained (Part 1): Generic Functions (video, YouTube, 12 min)

    A visual first look at why generics beat any, before the formal docs.

  3. TypeScript: Documentation - Generics (doc, typescriptlang.org, 25 min)

    The official reference for type variables, generic types, constraints and defaults.

  4. TypeScript: Documentation - More on Functions (doc, typescriptlang.org, 25 min)

    Shows how inference and extends constraints work in real generic functions such as longest().

  5. TypeScript Generics Explained (Part 2): Generics Type Constraints (video, YouTube, 10 min)

    Reinforces constraints with worked examples now that you have read the docs.

  6. TypeScript: Documentation - Object Types (doc, typescriptlang.org, 20 min)

    Covers generic object types and interfaces like Box<Type>, which leads into generic components.

  7. TypeScript Generics Explained (Part 3): Generic Interfaces (video, YouTube, 10 min)

    Practise generic interfaces before moving to classes and type-level features.

  8. TypeScript Generics: The Complete Guide (with Cheat Sheet) (article, DEV Community, 25 min)

    Consolidates inference, constraints and defaults, and shows how to diagnose common inference failures.

  9. TypeScript: Documentation - Mapped Types (doc, typescriptlang.org, 20 min)

    Generics get powerful when you transform one type into another with keyof.

  10. Conditional Types (doc, typescriptdocs.com, 25 min)

    Adds type-level if/else and infer, which build on constrained generics.

  11. TypeScript Generics Explained (Part 7): Conditional Types with Generics (video, YouTube, 12 min)

    A walkthrough that makes conditional types easier to follow.

  12. react-typescript-cheatsheet: generic-components.md (guide, React TypeScript Cheatsheet (GitHub), 20 min)

    Apply everything to a generic List<T> component, including the TSX <T,> syntax gotcha.

  13. How to Implement Generic Components in React with TypeScript (article, OneUptime, 25 min)

    Finish with larger practical examples, such as a generic Table and a ref-forwarding component, to build yourself.