Course contentsShow
← TypeScript
Lesson 1485 of 1,79634. The Limits of TypeScriptFree lesson

What Are Higher-Kinded Types?

Understanding HKTs as types that abstract over type constructors, like Array<T> or Promise<T> as first-class values.

What Are Higher-Kinded Types?

You'll learn: What higher-kinded types (HKTs) are conceptually and why TypeScript doesn't directly support them — a fundamental limitation that affects certain advanced abstraction patterns.

The Concept: Types That Abstract Over Type Constructors

In TypeScript, you're familiar with type constructors — types that take other types as parameters:

  • Array<T> takes a type T and produces Array<T>
  • Promise<T> takes a type T and produces Promise<T>
  • Record<K, V> takes types K and V and produces Record<K, V>

These are "first-order" generic types: they accept types and return types.

Higher-kinded types (HKTs) would let you abstract over these type constructors themselves as first-class values. Instead of working with Array or Promise directly, you'd treat the concept of "a type constructor that takes one argument" as a type parameter itself.

The Analogy: Functions vs Higher-Order Functions

Think of regular functions vs higher-order functions in JavaScript:

  • Regular function: Takes values, returns values
  • Higher-order function: Takes functions as parameters, returns functions

Similarly:

  • Regular generic type: Takes types, returns types (Array<number>)
  • Higher-kinded type: Would take type constructors as parameters (Container<Array> where Container works with any single-argument type constructor)

What TypeScript Can't Do

You cannot write something like:

// ❌ Not valid TypeScript
type MapOperation<F<_>, T, U> = F<T> => F<U>

Where F represents "any type constructor that takes one argument" — whether that's Array, Promise, or something custom.

TypeScript has no syntax for expressing "a generic type constructor as a parameter."

Why This Matters

HKTs enable powerful abstraction patterns in languages like Haskell or Scala. Without them, TypeScript can't easily express:

  • A single map function that works identically across Array, Promise, and custom containers
  • Functors, monads, and other category-theory-inspired patterns in a truly generic way
  • Libraries that abstract over which generic type you're using

Instead, TypeScript requires concrete implementations for each type constructor, or workarounds using complex type-level encoding techniques that simulate HKTs (with significant complexity costs).

Key Takeaway: Higher-kinded types let you treat type constructors like Array<T> or Promise<T> as first-class, parameterizable entities — but TypeScript fundamentally doesn't support this, limiting certain advanced generic abstraction patterns you might encounter in functional programming languages.