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

February 9, 2022 - 1 min read

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

TL;DR

// string literal type
type Greeting = "Hi, How Are you?";

// convert string literal type
// into lowercase format
type GreetingLowercase = Lowercase<Greeting>; // hi, how are you?

For example, let's say we have a string literal type like this,

// string literal type
type Greeting = "Hi, How Are you?";

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

It can be done like this,

// string literal type
type Greeting = "Hi, How Are you?";

// convert string literal type
// into lowercase format
type GreetingLowercase = Lowercase<Greeting>; // hi, how are you?

Now if you hover over the GreetingLowercase type you can see that the Hi, How Are you? string literal type is now converted into a lowercase format. Yay 🥳.

See the above code live in codesandbox.

That's all 😃!

Feel free to share if you found this useful 😃.