narrow-react-prop-types
Was er macht
Dieser Skill leitet den KI-Agenten an, optionale Props zu entfernen, die nur für Test- oder Story-Daten existieren. Er richtet sich an React-Entwickler, die strenge und genaue Komponententypen wollen.
Wann du ihn nutzt
- ✓Wenn die Props einer Komponente nur wegen Stories oder Tests breit und optional geworden sind.
- ✓Wenn du Zustände entfernen willst, die die echte App nie nutzt.
- ✓Wenn du React-Typen umbaust und sie aus dem laufenden Code ableiten willst.
Link zum Skill
https://github.com/humanlayer/humanlayer/blob/main/.claude/skills/narrow-react-prop-types/SKILL.mdKopiere ihn und füge ihn in deine KI ein (Claude, ChatGPT oder Cursor) mit der Bitte, den Anweisungen zu folgen.
So nutzt du ihn
Am einfachsten: Kopiere die Nachricht und füge sie in deine KI ein. Sie liest den Skill und folgt den Anweisungen.
Fertige Nachricht zum Einfügen
Für Claude Code, Codex oder Cursor: Führe den Befehl in deinem Projektordner aus, dann wird der Skill installiert.
Lade die SKILL.md herunter und lege sie in den Skills-Ordner deines Agenten.
Beispielanfrage an deine KI
“Diese React-Kartenkomponente hat zu viele optionale Props. Verenge die Typen auf das, was die echte App nutzt.”
5 neue Skills pro Woche. 1 Minute Lesezeit.
So funktioniert es
Der Agent findet zuerst die echten Aufrufstellen außerhalb von Tests und passt dann die Typen an sie an. Test- und Story-Code wird danach an die strengeren Typen angepasst.
Technischer Inhalt (originale SKILL.md)
Originaltext des Autors, auf Englisch, direkt von GitHub.
Narrow React Prop Types
Use this skill when a React component's props have been widened for stories, mocks, tests, or demos and now express states the live application does not enter.
The goal is to make component types describe the real live-code-path contract, then require stories/tests/mocks to adapt to that contract instead of weakening it.
Core Requirements
- Find the actual non-test, non-Storybook call sites before changing types.
- Treat live code paths as the source of truth for the prop contract.
- Do not preserve optional props only because they make Storybook, tests, or mock data easier.
- Keep props optional only when there are non-Storybook, non-test call sites which do not provide them and which have a good reason for not doing so.
- Types should not enable expressing states which are not observed in non-test, non-Storybook call sites.
- Types should be as strict as possible so code can be as simple as possible.
- Prefer deriving and extracting types from existing live-code-path values and APIs where possible.
Workflow
1. Identify the suspect component
Look for components with these signals:
- Large props interfaces with many optional fields.
- Optional callback calls such as
onSelect?.(...)oronArchive?.(...). - Fallback state handling such as
items ?? [],count ?? 0, orhandler && ...around values live code likely always supplies. - UI affordances that always render even though their callbacks are optional.
- Props that look demo-oriented, such as
defaultFoo, alternate handler shapes, or display toggles not used by live code.
Do not pick a target from a story or test alone. Use stories/tests only as supporting evidence that the type has been widened, not as evidence that a state is real.
2. Find every live usage
Search for all imports/usages of the component, exported prop type, and shared child primitives.
Classify call sites by whether they are live code paths or support code:
- Live code paths: app routes, wired components, providers, hooks, production package exports, and shared components used by those paths.
- Support code: Storybook stories, test files, fixtures, mocks, demo harnesses, and visual-only examples.
Only live code paths should determine what the component API supports.
3. Derive the real types from the live code paths
Read the live call sites and classify each prop:
- Required: every non-test, non-Storybook call site supplies it.
- Optional: at least one non-test, non-Storybook call site omits it and that omission is a meaningful runtime state.
- Removed: no non-test, non-Storybook call site uses it.
Nullability and optionality are different. If live code always passes a prop but the value can be empty, prefer a required nullable prop such as focusedItem: FocusedItem | null over focusedItem?: FocusedItem | null.
4. Tighten the public prop type
Update exported prop types to match only the states observed in live code paths.
The looser and more optional a type is, the more possible states the component has to reason about. Every optional prop creates another branch the component must handle, test, and keep correct. Prefer strict types that prevent impossible states instead of broad types that require defensive render logic.
If the component always renders an interactive affordance, require the handler that makes it work. Do not allow inert states like a visible menu item that calls onRename?.(...).
5. Derive and extract types where possible
Prefer deriving types from the live APIs instead of restating them manually:
Parameters<typeof fn>[0]for function argument types.ReturnType<typeof fn>for return types.Extract<Union, Shape>for narrowing a union to a real variant.React.Dispatch<React.SetStateAction<T>>for React state setters instead of approximating them as(value: T) => void.
Prefer explicit state type parameters when inference would widen or obscure the intended state shape:
const [dialogState, setDialogState] = useState<DialogState>({
id: null,
isOpen: false,
})
Avoid relying on implicit useState(...) inference when it produces broad nullable object shapes, string literal widening, or callback types that later need hand-written approximations.
6. Tighten internal child props too
Do not stop at the exported component if it passes broad props into child primitives.
If row/menu/button child components receive optional handlers only because the parent props were
Häufige Fragen
Brechen dabei meine Tests?
Tests und Stories müssen eventuell angepasst werden. Der Skill passt sie an die strengeren Typen an, statt die Typen aufzuweichen.
Prüft er zuerst die echte App?
Ja. Er findet die tatsächlichen Aufrufstellen außerhalb von Tests, bevor er Typen ändert.
Können manche Props optional bleiben?
Ja, aber nur wenn keine echte Aufrufstelle sie übergibt und es einen guten Grund gibt.
Details
Originalbeschreibung des Autors
narrow React component prop types to match live code paths
repo: humanlayer/humanlayer
Beliebtheit
- GitHub-Sterne
- 13k
- Platz im Ranking
- #11388
- Lizenz
- Apache-2.0
- Aktualisiert
- 31.10.2026
Kommentare
- …
Weitere Skills aus diesem Repository
asd-ste100
13kBringt deinem Agenten bei, verwirrendes Englisch in kurze Sätze mit nur einer Bedeutung umzuschreiben, die für Menschen und andere Software leicht zu lesen sind.
better-github-skill
13kHilft deinem Agenten, den Status eines Pull Requests zu prüfen, seine Review-Kommentare zu lesen und herauszufinden, warum ein CI-Build fehlgeschlagen ist, mit fertigen GitHub-Skripten.
calldiff
13kHilft deinem Agenten, die Ketten von Funktionsaufrufen in einer Codebasis zwischen zwei Git-Versionen zu vergleichen, damit eine Code-Prüfung sieht, welches Verhalten sich geändert hat.
chrome-devtools-cli
13kLässt deinen Agenten Chrome vom Terminal aus steuern, um Seiten zu öffnen, zu klicken, Formulare auszufüllen und Seiten-Snapshots für Browser-Automatisierung und Tests zu erstellen.
Ähnliche Skills
angular-developer
280kHilft deinem Agenten bei Angular-Code und gibt Tipps zur Projektstruktur. Nützlich für neue Projekte, einzelne Code-Teile sowie Performance und Barrierefreiheit.
frontend-a11y
280kHilft deinem Agenten, Weboberflächen für alle zugänglich zu machen. Sorgt dafür, dass Websites und Apps gut mit Screenreadern und Tastaturnavigation funktionieren.
frontend-patterns
280kLässt deinen Agenten moderne Muster in der Frontend-Entwicklung anwenden. Optimiert Performance, verwaltet State und folgt Best Practices für React und Next.js.