In this section, we are going to learn some advanced type system features such as generic types, mapped types, and lookup types.
Advanced features of the TypeScript type system
Generic types
Generic types can help us avoid using type casting and increase the reusability of our code by allowing us to declare (T) when a function, class, or method is consumed, as opposed to when it is declared:
function deserialize<T>(json: string): T {
return JSON.parse(json) as T;
}
interface User {
name: string;
age: number;
}
let user = deserialize<User>(`{"name":"Remo","age":28}`);
interface Rectangle {
width: number;
height: number;
}
let rectangle = deserialize<Rectangle>(`{"...