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
Syntax
Uppercase<StringType>
Parameters
| Parameter | Description |
|---|---|
StringType |
A string literal type (or union). |
Return value
The upper-cased literal type.
Examples
type Method = "get" | "post";
type HttpMethod = Uppercase<Method>; // "GET" | "POST"
const m: HttpMethod = "POST";
console.log(m);
Output
POST
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
| Version | Change |
|---|---|
| TypeScript 4.1 | Added |
Related
Capitalize<StringType>· Upper-case the first character of a string literal type: Capitalize<'click'> is 'Click'. Used to build names like onClick.template literal types· Build string literal types with template syntax: `on${string}` or combinations of unions like `${Size}-${Color}`.- TypeScript Utility Types · tutorial