Define generics in TypeScript

Intermediate
Developer
Student
Azure

Generics are code templates that you can define and reuse throughout your codebase. They provide a way to tell functions, classes, or interfaces what type you want to use when you call it.

Learning objectives

In this module, you will:

  • Identify use cases for generics.
  • Define a generic function.
  • Declare a generic interface.
  • Declare a generic class.
  • Implement generic constraints.

Prerequisites

  • Knowledge of TypeScript
  • Familiarity with JavaScript
  • Familiarity with TypeScript functions, interfaces, and classes.
  • Installed software: