0Pricing
TypeScript Academy · Lesson

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 type

Kinds, 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

  1. The HKT Problem in TypeScript
  2. Defining Type Constructors
  3. The Lightweight HKT Pattern
  4. Generic Functors and Mappers
← Back to TypeScript Academy