Skip to content
webtype.orgwebtype.org

    ↑↓ move · ⏎ open · esc close

    Strings

    Uncapitalize

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

    What it is

    The inverse of Capitalize, and the one you need when going the other way: turning getName back into name, or an event type Click into the handler key onClick’s payload name. Less used than its mirror, and for exactly that reason more often forgotten to exist.

    Examples

    • Uncapitalize<'Name'>
      →"name"
    • Uncapitalize<'HELLO'>
      →"hELLO"
    • Uncapitalize<Capitalize<'name'>>
      →"name"

      They compose back to where you started, for a first character that had a case to begin with.

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

    What it does not do

    • It does not lower-case the whole string, which Uncapitalize<"HELLO"> makes uncomfortably clear.
    • It is not a round trip in general. Only the first character is affected, so any information lost elsewhere stays lost.

    Takeaway

    Reach for it when deriving a property name back out of a method name — the inverse direction is where the missing key usually comes from.