Skip to main content

Generics

Introduction to Generics

0:00
LearnStep 1/2

Why Generics?

The Problem with any

Without generics, we often resort to any for flexible functions:

typescript

Generics to the Rescue

Generics let us capture the type and use it:

typescript

Generic Syntax

  • <T> - Type parameter (convention: T, U, V, K, V)
  • Placed after function name, before parameters
  • Can be inferred or explicitly specified
typescript