TypeScript 7 reference · Utility Types

TypeScript Uppercase<StringType> Utility Type

Turn a string literal type into upper case at the type level: Uppercase<'get'> is 'GET'.

TypeScript 7 Since 4.1

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

Uppercase<StringType>

Parameters

ParameterDescription
StringType A string literal type (or union).

Return value

The upper-cased literal type.

Examples

HTTP methodsTry it yourself
type Method = "get" | "post";
type HttpMethod = Uppercase<Method>; // "GET" | "POST"
const m: HttpMethod = "POST";
console.log(m);

Output

POST
With template literal typesTry it yourself
type Env = "dev" | "prod";
type EnvVar = `APP_${Uppercase<Env>}_URL`;
const v: EnvVar = "APP_PROD_URL";
console.log(v);

Output

APP_PROD_URL

Version history

VersionChange
TypeScript 4.1Added

Was this page helpful?