What is the difference between type-level and value-level programming in TypeScript?

Answer

TypeScript exists at two levels simultaneously. Value-level programming is regular JavaScript/TypeScript code that runs at runtime — variables, functions, classes, objects, conditional statements, loops. Type-level programming is computation that happens only at compile time in the type checker — generic types, conditional types, mapped types, template literal types, infer. The type level is a completely separate, Turing-complete language built into TypeScript's type system. At the type level: conditional types are if-else, mapped types are loops, recursive generics are recursion. Interesting property: any type computation that can be expressed in the type system is guaranteed to terminate (TypeScript has recursion depth limits). TypeScript engineers have implemented type-level: JSON parsers, arithmetic operations, string parsers, Fibonacci sequences, and more — all in the type system. Practical examples of type-level computation: Awaited<T> recursively unwraps promises, DeepPartial<T> recursively makes nested properties optional, template literal types compute string transformations. Understanding both levels is key to mastering advanced TypeScript.