string-manipulation
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.
type Capitalize<S extends string> = intrinsic Usage patterns
| Pattern | Purpose |
|---|---|
| Capitalize<'foo'> | Basic first-letter uppercase |
| `get${Capitalize<K>}` | Build getter names from field names |
| Capitalize<Uncapitalize<S>> | Normalize to a guaranteed capitalized form |
| Capitalize<K & string> | Narrow keyof T to strings before capitalizing |
Examples
type C = Capitalize<'foo'>; Result: 'Foo'
type Getters<T> = { [K in keyof T as `get${Capitalize<K & string>}`]: () => T[K] }; Generates getFoo, getBar, ... mapping from object keys
type U = 'apple' | 'banana';
type C = Capitalize<U>; Result: 'Apple' | 'Banana' — distributes over unions
type S = Capitalize<string>; Result: string when the input is not a literal
Gotcha
Only affects the FIRST character — the remainder is left as-is. Non-literal inputs widen to plain `string`.
Related utility types
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.
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.
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.
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