Course contentsShow
← TypeScript
Lesson 831 of 1,79619. Template Literal TypesFree lesson

Uppercase<T> for Full Capitalization

How Uppercase converts all characters in a string literal type to uppercase at the type level.

Uppercase<T> for Full Capitalization

What you'll learn: How the Uppercase<T> utility type converts all characters in a string literal type to uppercase at the type level.


The Core Idea

Uppercase<T> is one of TypeScript's built-in template literal manipulation utilities. It takes a string literal type and transforms every character to its uppercase equivalent at the type level—meaning this transformation happens during compilation, not at runtime.

Think of it like a "CAPS LOCK" key for your types. Just as CAPS LOCK transforms whatever you type into uppercase letters, Uppercase<T> transforms whatever string literal type you pass into an all-uppercase version.

How It Works

type Whisper = "hello world";
type Shout = Uppercase<Whisper>;  // "HELLO WORLD"

type Status = "loading" | "success" | "error";
type LoudStatus = Uppercase<Status>;  // "LOADING" | "SUCCESS" | "ERROR"

When you apply Uppercase<T> to a union of string literals, it distributes over each member, capitalizing them all individually.

Practical Applications

This becomes powerful when building type-safe APIs or naming conventions:

type EventName = "click" | "hover" | "focus";
type ConstantName = Uppercase<EventName>;  
// "CLICK" | "HOVER" | "FOCUS"

// Use in object keys
type EventConstants = {
  [K in EventName as Uppercase<K>]: K;
};
// { CLICK: "click", HOVER: "hover", FOCUS: "focus" }

Remember: this only transforms the type, not actual runtime string values. The transformation is purely for type-checking purposes.

Key Takeaway: Uppercase<T> converts all characters in a string literal type to uppercase at compile time, enabling type-safe uppercase naming patterns and conventions without runtime overhead.