Skip to content
Tutorials Center
My learning

Topics

TypeScript Reference ยท Utility Types

TypeScript Uppercase<S> utility type

Reference for Uppercase<S> in TypeScript: an intrinsic string type that converts literal types and template literal types to upper case, with examples.

Uppercase<S> turns a string literal type into the same literal with every letter in upper case. Uppercase<"get"> is "GET". It works on unions (each member is converted), on template literal types, and on type parameters that extend string.

It is one of four intrinsic string-manipulation types, together with Lowercase, Capitalize and Uncapitalize. They are implemented inside the compiler rather than written in TypeScript, because there is no way to express case conversion with conditional types alone. Typical uses are building constant-style names, HTTP method unions and event-key mappings.

TypeScript
type Verb = "get" | "post";
type Method = Uppercase<Verb>; // "GET" | "POST"

Try it

TypeScript Constant-style keys from a union

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or readFileSync(0)), it gets the next line from this box.

TypeScript Mapped type with renamed keys

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or readFileSync(0)), it gets the next line from this box.

Syntax

TypeScript
type Uppercase<S extends string> = intrinsic;
Name Description
S A string type: a literal, a union of literals, a template literal type or a type parameter constrained to string.

Returns: the string type with each character mapped to upper case using the same Unicode rules as String.prototype.toUpperCase at the type level.

Edge cases:

  • A union distributes: Uppercase<"a" | "b"> is "A" | "B".
  • Characters with no upper-case form are unchanged: Uppercase<"a-1"> is "A-1".
  • Uppercase<string> is not plain string: it is a narrower type that is assignable to string but not the other way round. A literal that is already upper case, such as "OPEN", is accepted; an arbitrary string needs an assertion.
  • The type-level mapping is locale-independent, like toUpperCase() (use toLocaleUpperCase() when you need locale rules at runtime).

Usage notes

  • The type is not applied to values: "abc".toUpperCase() returns string, not "ABC". You need an assertion or a typed wrapper to carry the literal type through.
  • Use keyof T & string in key remapping, because keys may be number or symbol.
  • Combine with template literal types to build families of names: `on${Capitalize<E>}` for handlers, `${Uppercase<M>}_REQUEST` for actions.
  • Applying it twice is idempotent; applying it to something already upper case changes nothing.
  • It has no runtime output; the generated JavaScript contains none of these types.