Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

TypeScript · Type Alias

Capitalize

Capitalize<StringType> converts the first character of a string-literal type to uppercase. It is an intrinsic compiler type commonly used with template literal and mapped types to generate names.

Since
4.1

How it works

Capitalize<StringType> is an intrinsic string-manipulation type that changes the first character of a string literal type to uppercase while leaving the remainder unchanged. It is useful inside template literal types and mapped types when generating consistently named APIs.

Syntax

Capitalize<StringType>

Parameters

NameTypeDescription
StringTypestring typeString-literal type whose first character is converted to uppercase.

Returns

A string-literal type with its first character converted to uppercase.

Key points

  • It changes only the first character of the input string-literal type.
  • It is part of TypeScript’s built-in intrinsic string-manipulation types.
  • The type is implemented by the compiler rather than declared in the standard .d.ts files.

Common mistakes

  • Capitalization follows JavaScript string runtime behavior and is not locale-aware.

Example: Capitalize union members

type EventName = "userCreated" | "orderPlaced";
type GetterName = `get${Capitalize<EventName>}`;

const getter: GetterName = "getUserCreated";
console.log(getter);

The type transforms each union member's first character, producing the allowed getter names.

When to use it

Generate getter names

Deriving method or property names from string-literal keys.

Transform string unions

Creating consistent event, command, or route names from unions.

Compose template literal types

Building typed APIs whose names follow a casing convention.

Interview questions

QWhat does Capitalize do?

Capitalize<StringType> converts the first character of a string literal type to its uppercase equivalent. For example, Capitalize<"hello, world"> becomes "Hello, world".

Follow-up: How does it differ from Uppercase? Uppercase transforms every character, whereas Capitalize transforms only the first character.

QHow does Capitalize work with unions?

It can transform each member of a string-literal union, so Capitalize<"foo" | "bar"> becomes "Foo" | "Bar". This makes it useful for deriving names without manually listing every result.

Follow-up: What happens with a non-literal string? The result cannot be narrowed to one concrete literal, so capitalization is most useful when the input retains literal information.

QHow can Capitalize help generate API property names?

Capitalize is commonly embedded in template literal types, such as get${Capitalize<Property>} , to generate names like getName. Mapped types can use those generated names as property keys.

Follow-up: Why might a mapped type intersect a key with string? Object keys can also be numbers or symbols, while the capitalization operation applies to string cases.

  • Uppercase
  • Lowercase
  • Uncapitalize
  • Template Literal Types
  • Mapped Types

Source: Documentation - Template Literal Types. Checked 2026-10-15.