0Pricing
TypeScript Academy · Lesson

Types as a Computation Language

Understand the type system as a pure functional language.

Types Are a Language

TypeScript has two languages living side by side. One is the value-level JavaScript you already know. The other is the type level, which runs entirely at compile time. In this course you learn to program in that second language.

The type system is a small, pure, functional language. You give it types as input and it computes types as output. None of it survives to runtime.

type Greeting = "hello";
type Loud = Uppercase<Greeting>;
// Loud is "HELLO" - computed by the type system

Types In, Types Out

A generic type is essentially a function from types to types. The type parameter is the argument, and the body is the return value.

Below, Boxed takes a type T and produces an object type that wraps it. Think of T as a parameter you pass in.

type Boxed<T> = { value: T };

type A = Boxed<number>; // { value: number }
type B = Boxed<string>; // { value: string }

All lessons in this course

  1. Types as a Computation Language
  2. Type-Level Conditionals
  3. Type-Level Recursion
  4. Distributive Conditional Types
← Back to TypeScript Academy