The interface-with-type Pattern
What you'll learn: How to create a generic interface that holds a type property, enabling you to "store" partially-applied type information in a way that TypeScript can recognize and manipulate.
The Pattern Explained
When simulating higher-kinded types in TypeScript, you need a way to represent "a type constructor that hasn't been fully applied yet." The interface-with-type pattern solves this by creating an interface with a generic type property—essentially a container that can hold type information without immediately applying it.
Think of it like a form with blank fields: the interface structure exists, but the actual type it represents is left as a placeholder (Type<A> property) that gets filled in later.
Why This Pattern Exists
TypeScript doesn't have true higher-kinded types, but you can simulate them by creating interfaces that act as "type constructors." The trick is to have an interface with a generic Type property:
interface ArrayHKT {
Type: Array<never>;
}
This interface doesn't create arrays—it represents the idea of the Array type constructor itself. The Type property is where the actual constructed type will live.
How It Works
You define an interface where the Type property uses a generic parameter. Later, you can "apply" a type argument by referencing this property:
interface Container<A> {
Type: A;
}
// "Apply" the type by accessing the Type property
type Applied = Container<string>['Type']; // string
The interface holds the type relationship, and indexed access (['Type']) extracts it when needed. This lets you pass around unapplied type constructors as if they were values, then apply them in generic contexts.
Key Takeaway: The interface-with-type pattern uses an interface with a generic Type property to represent partially-applied type constructors, enabling type-level abstraction that mimics higher-kinded types in TypeScript.