Lesson 2.1

Generic functions and inference

A type parameter links an input type to an output type. Most of the skill is letting inference do the work rather than annotating call sites.

Duration
13m
Level
Intermediate
Students
19k students

Overview

A type parameter links an input type to an output type. Most of the skill is letting inference do the work rather than annotating call sites.

In this lesson you will:

  • Relate argument and return types with a type parameter
  • Let inference fill in type arguments at the call site
  • Recognise when a generic adds nothing over a union

Resources

TypeScript handbook

The official reference for the tools used in this lesson.