How to convert a string literal type into an uppercase format in TypeScript?

February 8, 2022 - 1 min read

To convert a string literal type into an uppercase format, you can use the built-in Uppercase type that comes with TypeScript.

TL;DR

// lowercase string literal type
type Greeting = "hello";

// convert string literal type
// into uppercase format
type GreetingUppercase = Uppercase<Greeting>; // HELLO

For example, let's say we have a string literal type that is in the lowercase format like this,

// lowercase string literal type
type Greeting = "hello";

Now to convert the string literal type into uppercase let's use the Uppercase built-in type and pass the Greeting type into it using the angled bracket (<>) syntax.

It can be done like this,

// lowercase string literal type
type Greeting = "hello";

// convert string literal type
// into uppercase format
type GreetingUppercase = Uppercase<Greeting>; // HELLO

Now if you hover over the GreetingUppercase type you can see that the hello string literal type is now converted into an uppercase format. Yay 🥳.

See the above code live in codesandbox.

That's all 😃!

Feel free to share if you found this useful 😃.