String literal transformation
Derive a lowercase-leading string literal type from an uppercase or capitalized literal.
TypeScript · Type Alias
Uncapitalize is a built-in intrinsic type that converts the first character of a string type to lowercase. The rest of the string remains unchanged.
Uncapitalize is a built-in intrinsic string manipulation type that transforms the first character of a string type to its lowercase equivalent while leaving the remaining characters unchanged. Its behavior uses JavaScript string operations and is not locale-aware.
Uncapitalize<StringType>| Name | Type | Description |
|---|---|---|
StringType | string type | The string type whose first character is transformed to lowercase. |
A string type with its first character converted to lowercase.
type UppercaseGreeting = "HELLO WORLD";
type LowercaseGreeting = Uncapitalize<UppercaseGreeting>;
const greeting: LowercaseGreeting = "hELLO WORLD";
console.log(greeting);Uncapitalize lowers only the first character of the string literal type.
Derive a lowercase-leading string literal type from an uppercase or capitalized literal.
Compose casing transformations with template literal types when generating related compile-time string forms.
Uncapitalize<StringType> converts the first character of StringType to a lowercase equivalent. It does not lowercase the rest of the string.
Follow-up: What happens to the remaining characters? They are preserved unchanged; only the first character is transformed.
It is an intrinsic type built into the TypeScript compiler for string manipulation. These intrinsic types are not declared in the TypeScript library .d.ts files.
Follow-up: Why are they compiler intrinsics? The documentation says they are built into the compiler for performance.
For an input such as "HELLO WORLD", Uncapitalize produces "hELLO WORLD". This makes it useful for deriving related string literal types without runtime code.
Follow-up: How does its behavior differ from Lowercase? Lowercase transforms every character, whereas Uncapitalize changes only the first character.
UppercaseLowercaseCapitalizeTemplate Literal Types