Type Constructors

This lesson explains theoretical foundations of generic types and gives you a glimpse into category theory. It provides a mental model that will prove useful in the next chapters.

We'll cover the following

Two worlds

Type constructor is a function (not a regular function, a mathematical function) that takes a type and returns a new type (based on the original type).

Notice that a generic interface with only one type argument is exactly that. For example, the FormField type from the previous lesson is a function with one type argument, T. It takes a type (e.g. string) and returns a new type (FormField<string> or { value?: string; defaultValue: string; isValid: boolean; }).