The HKT Problem in TypeScript
Understand why generic type constructors are hard.
What Is a Higher-Kinded Type
A higher-kinded type (HKT) abstracts not over a concrete type, but over a type constructor: something like Array or Promise that needs an argument to become a real type.
Array alone is not a type. Array<string> is. Array is a function on types, and HKTs let us be generic over such functions.
type StringArray = Array<string>;
type NumberArray = Array<number>;
// Array by itself is a type constructor, not a typeKinds, Briefly
Just as values have types, type constructors have kinds. A plain type like number has kind *. Array has kind * -> *: give it one type, get a type back. Being generic over these is "higher-kinded".
type ValueLike = number; // kind *
// Array needs one argument: kind * -> *
// Map needs two arguments: kind * -> * -> *All lessons in this course
- The HKT Problem in TypeScript
- Defining Type Constructors
- The Lightweight HKT Pattern
- Generic Functors and Mappers