string-manipulation
Uppercase<S>
Compile-time intrinsic that converts a string literal type S to its uppercase form. Introduced in TS 4.1 alongside template literal types.
type Uppercase<S extends string> = intrinsic Usage patterns
| Pattern | Purpose |
|---|---|
| Uppercase<'hello'> | Basic uppercase of a literal |
| Uppercase<`get_${string}`> | Combine with template literal types |
| Uppercase<T> & string | Ensure result stays assignable to string |
| as Uppercase<'x'> | Assertion to lock a value's literal case |
Examples
type H = Uppercase<'hello'>; Result: 'HELLO'
type Env = 'dev' | 'prod';
type LoudEnv = Uppercase<Env>; Distributes over unions: 'DEV' | 'PROD'
type Header<K extends string> = `X-${Uppercase<K>}`;
type H = Header<'id'>; // 'X-ID' Composing with template literal types
type S = Uppercase<string>; Result: string (widens when the input is not a literal)
Gotcha
Only affects string LITERAL types — passing a plain `string` widens the result back to `string`. Purely a compile-time transformation, so no runtime toUpperCase call is generated.
Related utility types
Lowercase<S>
Intrinsic string type manipulator that converts each character of literal S to lowercase. Available since TS 4.1 and evaluated by the compiler with no runtime cost.
Capitalize<S>
Intrinsic string type utility that uppercases the first character of literal string S, leaving the rest unchanged. Enables typed camelCase-to-PascalCase and getter-name construction.
Uncapitalize<S>
Intrinsic type utility that lowercases the first character of literal S, leaving the rest unchanged. The inverse of Capitalize and widely used for PascalCase-to-camelCase mappings.
Record<K, V>
Creates an object type whose keys come from the union K and whose values all have type V. Useful for lookup tables, dictionaries, and enum-keyed maps.
← All TS utility types · TypeScript vs JavaScript · any vs unknown vs never