TypeScript Capitalize <StringType> Utility Type
Last Updated :
24 Apr, 2025
In this article, we are going to learn about Capitalize<StringType> Template Literal Type in Typescript. TypeScript is a popular programming language used for building scalable and robust applications. One of the features of Typescript is Capitalize<StringType> Template Literal Type which is a built-in utility type that helps with string manipulation. It helps to capitalize the first letter of each word in a given StringType.
Syntax:
type CapitalizedString = Capitalize<StringType>;
Where -
- Capitalize is the utility itself.
- StringType is the type you want to capitalize. This is the input type that you want to capitalize. It can be a string literal type, a string union type, or any other string type.
Example 1: In this example, MyString is defined as "hello world," and CapitalizedString is defined as Capitalize<MyString>. The result is that CapitalizedString will be of type "Hello", with the first letter capitalized.
JavaScript
type MyString = "hello";
type CapitalizedString = Capitalize<MyString>;
const result: CapitalizedString = "Hello";
console.log(result);