capitalize
The capitalize() method returns a new string with the first letter uppercased.
Interactive example
Syntax
typescript
function capitalize<
GenericInput extends string
>(
input: GenericInput
): Capitalize<GenericInput>Parameters
input: The string to modify. The type is generic (GenericInput extends string) to allow precise literal type inference.
Return value
A new string with the first letter uppercased. The return type is precisely inferred thanks to TypeScript's Capitalize<GenericInput> utility type.
See also
uncapitalize- Lowercases the first lettertoUpperCase- Converts the whole string to uppercasetoLowerCase- Converts the whole string to lowercase
Sources
- TypeScript - Capitalize<StringType> - TypeScript utility type for inference
