Normalize literal types
Derive lowercase variants of string literal types for compile-time validation.
TypeScript · Type Alias
Lowercase<StringType> converts every character in a string type to its lowercase equivalent. Use it to derive normalized string-literal types, including names built with template literal types.
Lowercase is an intrinsic string manipulation type that transforms every character in a string type to its lowercase equivalent. It is especially useful inside template literal types when generating normalized names such as cache keys.
Lowercase<StringType>| Name | Type | Description |
|---|---|---|
StringType | string | The string type whose characters should be converted to lowercase. |
A string type with every character converted to its lowercase equivalent.
.d.ts files for its implementation will not find one.type Greeting = "Hello, world";
type QuietGreeting = Lowercase<Greeting>;
const greeting: QuietGreeting = "hello, world";
console.log(greeting);Transforms a string literal type into its lowercase form, allowing the compiler to check the normalized value.
Derive lowercase variants of string literal types for compile-time validation.
Build prefixed identifiers whose input portion must use lowercase casing.
Enforce naming conventions in generic template literal types.
Lowercase<StringType> is an intrinsic string manipulation type. It converts each character in the supplied string type to its lowercase equivalent.
Follow-up: How can it be used with a generic? Define a constraint such as Str extends string, then use Lowercase<Str> inside a template literal type to construct a normalized result.
It can be embedded in a template literal type to derive a new string literal type. For example, id-${Lowercase<"MY_APP">} produces "id-my_app".
Follow-up: Why is this useful in large codebases? It lets APIs encode naming conventions in types, so inconsistent casing becomes a compile-time error.
The type parameter represents the input string type, and the result is the same string with every character converted to lowercase. TypeScript includes it as a built-in compiler intrinsic for performance.
Follow-up: What related utilities exist? Uppercase transforms every character to uppercase, while Capitalize and Uncapitalize affect only the first character.
UppercaseCapitalizeUncapitalizeTemplate Literal TypesIntrinsic String Manipulation Types