Skip to content
webtype.orgwebtype.org

    ↑↓ move · ⏎ open · esc close

    Strings

    Capitalize

    Upper-cases the first character and leaves the rest alone.

    What it is

    The building block for every getter-name and event-name type you will write. Combined with a template literal it turns name into getName, which is the single most common reason people reach for template literal types at all.

    Examples

    • Capitalize<'hello world'>
      →"Hello world"
    • `get${Capitalize<'name'>}`
      →"getName"

      The getter idiom, in one line. This is what Capitalize is for.

    • Capitalize<''>
      →""

    Each resolved type above was printed by TypeScript 6.0.3, not written by hand.

    What it does not do

    • It does not touch anything after the first character. Capitalize<"hello world"> capitalises one letter, not each word.
    • It does not know what a word is. Title casing needs you to split on spaces yourself first.

    Takeaway

    ${Prefix}${Capitalize<K & string>} is the shape behind every generated method name. The & string is there because a key can be a symbol.