April 2018
Beginner
536 pages
13h 21m
English
Lookup types are another advanced type system feature that allow us to combine the keyof operator with generic and object literals to create advanced type annotations. Let's look at an example:
function filterByProperty<T, K extends keyof T>( property: K, entities: T[], value: T[K]) { return entities.filter(e => e[property] === value);}
The preceding function takes two generic type arguments:
The function also expects two arguments: