Type Argument Propagation
Learn how propagated generic type arguments in TypeScript 3.4 improve type inference for composed generic functions. Understand how this feature simplifies typings in functional programming patterns and popular libraries, enabling cleaner, more concise code.
We'll cover the following...
We'll cover the following...
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);
}
Next, you decide to generalize the getIds function so that it works on any collection of ...