How to convert the first letter of a string literal type into a lowercase format or uncapitalize in TypeScript?

February 11, 2022 - 1 min read

To convert the first letter of string literal type into a lowercase format or uncapitalize, you can use the built-in Uncapitalize type that comes with TypeScript.

TL;DR

// string literal type
type Greeting = "HELLO WORLD";

// convert first letter of
// string literal type
// into lowercase format or uncapitalize
type GreetingUncapitalized = Uncapitalize<Greeting>; // hELLO WORLD

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

// string literal type
type Greeting = "HELLO WORLD";

Now to uncapitalize the string literal type let's use the Uncapitalize 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 = "HELLO WORLD";

// convert first letter of
// string literal type
// into lowercase format or uncapitalize
type GreetingUncapitalized = Uncapitalize<Greeting>; // hELLO WORLD

Now if you hover over the GreetingUncapitalized type you can see that the HELLO WORLD string literal type is now uncapitalized. Yay 🥳.

See the above code live in codesandbox.

That's all 😃!

Feel free to share if you found this useful 😃.