Lowercase<StringType> Type
It helps to convert each character in the string to a lowercase equivalent.
type LowercaseString = Lowercase<"w3wiki">; // "w3wiki"
Example: In this example, we will see an example of using Lowercase<StringType> Template Literal. Uppercase will convert each character in the string to a lowercase equivalent resulting in w3wiki
Javascript
type gfg = "w3wiki" type geek = Lowercase<gfg> const result: geek = "w3wiki" ; console.log(result) |
Output:
TypeScript Intrinsic String Manipulation Type
In this article, we are going to learn about Intrinsic String Manipulation Types in Typescript. TypeScript is a popular programming language used for building scalable and robust applications. In TypeScript, you can use intrinsic string manipulation types to transform string literal types to uppercase, lowercase, capitalize the first letter, or uncapitalize (lowercase the first letter). These string manipulation types are part of TypeScript’s template literal types and can be helpful for enforcing proper string formatting at the type level.
These are the following types of intrinsic string manipulation:
Table of Content
- Uppercase
- Uncapitalize
- Lowercase
- Capitalize
Syntax:
type UppercaseString = Uppercase<"stringliteral">; // for upper case
type LowercaseString = Lowercase<"StringLiteral">; // for lowercase
type CapitalizedString = Capitalize<"stringliteral">; // for capitalize
type UncapitalizedString = Uncapitalize<"StringLiteral">; // for uncapitalize
where–
- Uppercase, Lowercase, Capitalize, and Uncapitalize are the intrinsic string manipulation types.
- “stringliteral” and “StringLiteral” are examples of string literal types to which these transformations are applied.