String Manipulation Types
TypeScript ships four intrinsic string manipulation utility types — Uppercase, Lowercase, Capitalize, and Uncapitalize — that transform string literal types at the type level. They operate purely in the type system: there is no runtime code, and the transformation happens during type checking, not execution. Combined with template literal types, they let you derive precise types for event names, CSS properties, getter names, and other string-shaped APIs. This page covers each one, how they distribute over unions, and the powerful patterns they unlock.
The four intrinsics
Each utility takes a string literal type and returns a transformed string literal type. They are “intrinsic,” meaning they are implemented inside the compiler rather than in TypeScript itself.
type Up = Uppercase<"hello">; // "HELLO"
type Down = Lowercase<"HELLO">; // "hello"
type Cap = Capitalize<"hello">; // "Hello"
type Uncap = Uncapitalize<"Hello">; // "hello"
Uppercase and Lowercase transform the whole string; Capitalize and Uncapitalize only touch the first character. On a non-literal string, they resolve to string, since there is nothing concrete to transform.
| Utility | Effect | Example |
|---|---|---|
Uppercase<S> | all characters upper | "abc" → "ABC" |
Lowercase<S> | all characters lower | "ABC" → "abc" |
Capitalize<S> | first character upper | "abc" → "Abc" |
Uncapitalize<S> | first character lower | "Abc" → "abc" |
Distributing over unions
When applied to a union of string literals, each utility distributes across every member, transforming them independently. This makes them ideal for normalizing sets of string keys.
type Method = "get" | "post" | "delete";
type Loud = Uppercase<Method>; // "GET" | "POST" | "DELETE"
type Direction = "north" | "south";
type TitleCase = Capitalize<Direction>; // "North" | "South"
Because the transformation is per-member, a union of n literals produces a union of n transformed literals — a property heavily used when generating typed APIs from a fixed set of names.
Building event handler names
The classic use case combines Capitalize with template literal types to derive onClick-style handler names from a union of event names. This is exactly how typed event-prop APIs are generated.
type EventName = "click" | "focus" | "scroll";
type Handlers = {
[E in EventName as `on${Capitalize<E>}`]: (event: Event) => void;
};
// { onClick: ...; onFocus: ...; onScroll: ... }
const handlers: Handlers = {
onClick: () => {},
onFocus: () => {},
onScroll: () => {},
};
The key remapping as \on${Capitalizecapitalizes each event name and prefixeson`, producing strongly typed handler keys with no manual duplication — see mapped types.
Deriving getter names from properties
Another common pattern generates getter method names from object keys, again pairing Capitalize with a mapped type and keyof.
interface State {
name: string;
age: number;
}
type Getters<T> = {
[K in keyof T as `get${Capitalize<string & K>}`]: () => T[K];
};
type StateGetters = Getters<State>;
// { getName: () => string; getAge: () => number }
The string & K intersection narrows the key to a string before capitalizing it, which is required because keyof can include symbol. The result is a typed accessor interface derived entirely from State.
These utilities are type-level only — they emit no JavaScript. To transform a string at runtime you still need
String.prototype.toUpperCase()and friends; the utility types just describe the resulting types.
Best Practices
- Use these intrinsics with template literal types to derive key names instead of hand-writing them.
- Pair
Capitalizewith key remapping (as) in mapped types to build handler or getter shapes. - Narrow keys with
string & Kbefore transforming, sincekeyofmay includesymbol. - Remember they distribute over unions, so one utility transforms an entire set of literals at once.
- Do not expect runtime behavior — reach for
.toUpperCase()/.toLowerCase()for actual values. - Combine
UncapitalizewithLowercasewhen normalizing inconsistent external string keys. - Keep the source union or interface as the single source of truth; derive the rest with these types.