Skip to content

Fix wrong variable name and API in README.invariant.md "Documenting impossible states" example #29

@ooloth

Description

@ooloth

Why

The "Documenting impossible states" example uses emojiMap.get(symbol) — a Map API call on a nonexistent variable — while the real code uses plain object bracket access on a variable named emojiLabel, so the snippet is factually wrong and will not compile.

Current state

utils/errors/README.invariant.md line 36:

const ariaLabel = emojiMap.get(symbol)
invariant(ariaLabel, 'Emoji must have aria-label', { symbol })
// Documents that our emoji map should be complete

ui/elements/emoji.tsx declares const emojiLabel = { … } as const and accesses it as const ariaLabel = emojiLabel[symbol]. There is no emojiMap variable and no .get() call anywhere in that file.

Ideal state

  • The example matches the actual code: const ariaLabel = emojiLabel[symbol].
  • A reader can copy the snippet and have it reflect what the codebase actually does.

Starting points

  • utils/errors/README.invariant.md — line 36, the "Documenting impossible states" example
  • ui/elements/emoji.tsx — line 3 (const emojiLabel), line 30 (emojiLabel[symbol])

QA plan

  1. Open utils/errors/README.invariant.md and read the "Documenting impossible states" example — expect emojiLabel[symbol] (plain object bracket access, correct variable name).
  2. Open ui/elements/emoji.tsx — expect the same expression on line 30.

Done when

The "Documenting impossible states" example uses emojiLabel[symbol], matching the real variable name and access pattern in ui/elements/emoji.tsx.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions