Type Argument Propagation

This lesson talks about an interesting language feature related to generic functions introduced in TypeScript 3.4.

Overview #

Let’s have a look at the following example. Imagine that you’re fetching a collection of objects from some backend service and you need to map this collection to an array of identifiers.

interface Person {
  id: string;
  name: string;
  birthYear: number;
}

function getIds(persons: Person[]) {
    return persons.map(person => person.id);
}

Get hands-on with 1200+ tech skills courses.