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

← All TS utility types · TypeScript vs JavaScript · any vs unknown vs never