What it is and why to use it
Intrinsic string-manipulation types transform string literal types at compile time. Uppercase and Lowercase change all letters, while Capitalize and Uncapitalize change the first character. They are useful for describing naming conventions in an API without repeating every derived spelling.
Common mistakes and limitations
These utilities do not call toUpperCase on runtime values. They are not locale-aware natural-language formatting rules. A broad string input may not provide the finite set of names that a precise literal union does.
Run this example
Use TypeScript 5.8 or later with strict checking and an ES2022 target. Save each complete example independently as example.ts, compile it, then run the generated JavaScript with a compatible Node.js installation. Compiler-only options below affect checking; they do not add runtime validation.
Terminal — compile and run
npx tsc example.ts --strict --target ES2022 --module commonjs
node example.jsSyntax
type EventName = `on${Capitalize<"save" | "load">}`;Examples
Uppercase, Lowercase and Capitalize Types
Standalone TypeScript 5.8+ example; expected output is explained below.
type EventName = `on${Capitalize<"save" | "load">}`;
type Loud = Uppercase<"ready">;
const event: EventName = "onSave";
const status: Loud = "READY";
console.log(event + ": " + status);- Capitalize transforms save and load into Save and Load inside the template literal.
- Prefixing on creates the allowed event names onSave and onLoad.
- Uppercase derives the exact READY type. No runtime conversion occurs; the written values already have those spellings.
- Expected output: onSave: READY
Best practices
- These utilities do not call toUpperCase on runtime values. They are not locale-aware natural-language formatting rules. A broad string input may not provide the finite set of names that a precise literal union does.
- Keep external-input validation separate from compile-time type descriptions.
Runtime & versions
Compiled to JavaScript. Feature availability depends on the language and runtime version used by your project; consult the official reference below.
TypeScript Handbook