Uppercase, Lowercase, Capitalize, Uncapitalize String Utilities
You'll learn how to transform string literal types using TypeScript's built-in intrinsic string manipulation utilities for template literals.
What Are Intrinsic String Utilities?
TypeScript provides four special utility types that manipulate string literal types at the type level: Uppercase<T>, Lowercase<T>, Capitalize<T>, and Uncapitalize<T>. These don't change runtime values—they transform the type of a string literal to match the transformed case.
Think of them as "find and replace" for types: if you have a type "hello", Uppercase<"hello"> produces the type "HELLO". This is incredibly useful when working with template literals, APIs with naming conventions, or code generation patterns.
The Four Utilities
type Greeting = "hello world";
type Shouting = Uppercase<Greeting>; // "HELLO WORLD"
type Whispering = Lowercase<Greeting>; // "hello world"
type Proper = Capitalize<Greeting>; // "Hello world"
type Casual = Uncapitalize<Greeting>; // "hello world"
Practical Use Cases
These shine with template literal types:
type HttpMethod = "get" | "post" | "put" | "delete";
type UpperMethod = Uppercase<HttpMethod>; // "GET" | "POST" | "PUT" | "DELETE"
type EventName = "click" | "hover";
type Handler = `on${Capitalize<EventName>}`; // "onClick" | "onHover"
They're also useful for mapping object keys:
type ApiRoutes = { user: string; product: string };
type UpperKeys = { [K in keyof ApiRoutes as Uppercase<K & string>]: ApiRoutes[K] };
// { USER: string; PRODUCT: string }
Key Takeaway: Use Uppercase, Lowercase, Capitalize, and Uncapitalize to transform string literal types, enabling type-safe naming conventions and template literal patterns without runtime overhead.