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

Why TypeScript Lacks True HKTs

TypeScript's type system is structural and lacks the ability to treat type constructors as variables or parameters.

Why TypeScript Lacks True HKTs

You'll learn: Why TypeScript's structural type system cannot treat type constructors (like Array or Promise) as variables or parameters, despite its powerful type-level capabilities.


The Core Limitation

In the previous lesson, you learned what Higher-Kinded Types are: the ability to abstract over type constructors themselves. Languages like Haskell let you write generic code that works with any container type—Array, Promise, Tree, etc.—by treating these constructors as values at the type level.

TypeScript fundamentally cannot do this. The reason lies in how TypeScript's type system works: it's structural and designed to gradually layer onto JavaScript, not to support this level of abstraction.

Why This Matters: Structural Typing vs Higher Abstraction

TypeScript checks types by their shape (structure), not by their name or identity. When you write a generic like <T>, T represents a concrete type (number, string, an object shape). You can pass types as parameters.

But you cannot pass a type constructor like Array or Promise as a parameter. There's no syntax to say "give me any single-argument type constructor" and then apply it later. Type constructors aren't first-class citizens at the type level—they can't be assigned to type variables.

The Missing Piece

Imagine wanting to write something like this (pseudo-syntax):

// NOT VALID TYPESCRIPT
type Container<F<_>> = <T>(value: T) => F<T>

Here, F would be a type constructor variable—something that takes a type and returns a type (like how Array takes number and gives you Array<number>).

TypeScript has no way to express this. You can't write F<_> or treat F as something that expects another type parameter. The type system simply doesn't have this feature.

Why TypeScript Made This Choice

TypeScript's design goals prioritize:

  • Compatibility with JavaScript: types are erased at runtime
  • Structural flexibility: types describe shapes, not rigid contracts
  • Gradual adoption: the type system layers onto existing JS code

Supporting true Higher-Kinded Types would require a fundamentally different type system—one that's more rigid, nominal, and complex. It would make TypeScript harder to learn and could break compatibility with JavaScript's dynamic nature.


Key Takeaway: TypeScript's structural, gradual type system cannot treat type constructors (like Array or Promise) as variables or parameters, which prevents true Higher-Kinded Types—a trade-off made to maintain JavaScript compatibility and approachability.