Type alias CapitalizeFirst<T>

CapitalizeFirst<T>: T extends `${infer First}${infer Rest}`
    ? `${Capitalize<First>}${Rest}`
    : T

Capitalizes the first character of a string literal type while preserving the rest. This is particularly useful when you need to transform string literal unions into their capitalized counterparts.

Type Parameters

  • T extends string

    The string literal type to capitalize

Example

type Category = "software" | "health" | "philosophy";
type Result = CapitalizeFirst<Category>; // "Software" | "Health" | "Philosophy"

type Single = CapitalizeFirst<"hello">; // "Hello"