How do the built-in intrinsic string manipulation types (Uppercase, Lowercase, Capitalize, Uncapitalize) work with template literal types?
Short answer
These four built-in generic utility types transform a string literal type's CASING at the type level (mirroring their runtime string method equivalents), and are most commonly combined with template literal types to systematically derive new property/method names with consistent…
Advertisement
AModel answer
These four built-in generic utility types transform a string literal type's CASING at the type level (mirroring their runtime string method equivalents), and are most commonly combined with template literal types to systematically derive new property/method names with consistent casing conventions.
type EventName<T extends string> = `on${Capitalize<T>}`;
type ClickEvent = EventName<'click'>; // 'onClick'
type HoverEvent = EventName<'hover'>; // 'onHover'Real-world example
Deriving consistent event-handler prop names (onClick, onHover) automatically from a base set of event name literals.
Likely follow-ups
- Do these intrinsic types have any runtime equivalent, or do they exist purely at the type level?
Related topics