SuperAPI AI Directory

clean-code-ts-react

Coding & development

View repository

Updated 10-15 15:31

About this skill

Robert C. Martin (Uncle Bob) TypeScript 5.x + React 19 Best Practices

Craftsmanship principles from Robert C. Martin's Clean Code (2008), re-expressed for modern TypeScript and React. Contains 61 rules across 11 categories, prioritized by cognitive cost across a code change's lifetime. Examples use TS 5.x and React 19 idioms — but the rules are about timeless principles, not specific APIs.

What Makes This Skill Different

Three things set this apart from a generic clean-code copy:

  1. Modern idioms as vehicle. Examples use TS 5.x (satisfies, branded types, discriminated unions, const type parameters) and React 19 (function components, hooks, use(), Server Components where relevant). But the rule is always the principle, never the syntax.
  2. "When NOT to apply" is first-class. Every rule has 2-3 concrete scenarios where the principle should bend — not generic disclaimers, real situations. Loop counters can be i. Single-use code shouldn't be DRY. Some HOCs are unavoidable.
  3. Meta category for principle conflicts. Category 11 names the most common tensions explicitly — DRY vs Single Responsibility, small functions vs deep modules (Ousterhout), type precision vs ergonomic APIs, tests as spec vs documentation. The mark of seniority is knowing which to bend.

When to Apply

Reference these guidelines when:

  • Writing new TypeScript or React code and wanting craftsmanship feedback
  • Reviewing a pull request for clarity, naming, or abstraction
  • Refactoring existing code for readability or maintainability
  • Designing function, hook, or component APIs
  • Deciding whether to extract, abstract, or duplicate
  • Resolving a tension between two clean-code rules (see Category 11)

Skip this skill and use:

  • react for React 19 API patterns (concurrent rendering, Server Components, ref-as-prop, useActionState, <Context>-as-provider)
  • typescript for compiler performance, tsconfig tuning, type-system perf
  • refactor for mechanical refactoring workflows
  • tdd for the TDD workflow itself

Rule Categories by Priority

Order reflects cognitive cost across a change's lifetime (read → understand → modify → verify → ship → maintain). Earlier stages cascade — bad names taint every read.

Priority Category Impact Prefix Rules
1 Meaningful Names CRITICAL name- 8
2 Functions, Components & Hooks CRITICAL func- 8
3 Self-Documentation (Types & Comments) HIGH doc- 5
4 Formatting (Beyond Prettier) HIGH fmt- 4
5 Error Handling HIGH err- 7
6 Data Shape & Immutability MEDIUM-HIGH data- 6
7 Boundaries MEDIUM-HIGH bound- 4
8 Composition over Inheritance MEDIUM-HIGH comp- 6
9 Tests MEDIUM test- 5
10 Emergence & Simple Design MEDIUM emerge- 4
11 Meta: When Principles Conflict MEDIUM meta- 4

Total: 61 rules.

Quick Reference

1. Meaningful Names (CRITICAL)

2. Functions, Components & Hooks (CRITICAL)

3. Self-Documentation: Types & Comments (HIGH)

4. Formatting Beyond Prettier (HIGH)

5. Error Handling (HIGH)

6. Data Shape & Immutability (MEDIUM-HIGH)

7. Boundaries (MEDIUM-HIGH)

8. Composition over Inheritance (MEDIUM-HIGH)

9. Tests (MEDIUM)

10. Emergence & Simple Design (MEDIUM)

11. Meta: When Principles Conflict (MEDIUM)

This is the signature category — explicit guidance on when one clean-code principle yields to another.

How to Use

For an ad-hoc question ("is this naming OK?", "should I extract this?"), jump straight to the relevant rule file via the Quick Reference above.

For a code review or refactor, scan the categories in priority order — names and function shape first (highest cascade), then errors and data shape, then composition and tests. The category-major sweep is more efficient than file-major.

When two principles seem to disagree, read the corresponding Meta rule (Category 11). Pick the principle that wins, and document the call.

Reference Files

File Description
references/_sections.md Category definitions and ordering
assets/templates/_template.md Template for adding new rules
metadata.json Version and reference information

Related Skills

  • .experimental/clean-code — Original language-agnostic clean code (Java examples). This skill is the TS+React sibling.
  • .curated/react — React 19-specific patterns (Server Components, concurrent rendering, ref-as-prop).
  • .curated/typescript — TS compiler performance and tsconfig tuning.
  • .curated/refactor — Mechanical refactoring workflows.
  • .curated/tdd — The TDD workflow itself.