К основному содержанию
скилл Claude Code CX Codex Cursor GitHub Copilot

narrow-react-prop-types — скилл для Claude Code: как ставить

Скилл сужает типы пропсов React-компонента до контракта, который реально используется в живом коде, и заставляет сторис и тесты подстроиться под него.

Установить в Claude Code · Через Skills CLI (Vercel) Все способы и платформы ↓
npx skills add humanlayer/skills --skill narrow-react-prop-types -a claude-code
Открыть на GitHub

Что делает narrow-react-prop-types

Скилл разбирает React-компонент, чьи типы пропсов раздулись под сторис, моки и демо, и возвращает их к контракту живого кода. Сначала ищет подозрительные интерфейсы: много опциональных полей, вызовы onSelect?.(...), подстраховки вроде items ?? []. Потом проходит по всем импортам и делит места вызова на живой код и служебный: сторис, тесты, фикстуры. Источник правды — только живой код.

Опциональность и nullable — разные вещи. Если живой код всегда передаёт проп, а значение бывает пустым, скилл советует сделать его обязательным с | null. Типы предлагает выводить из существующих API: Parameters<typeof fn>[0], ReturnType<typeof fn>, Extract<Union, Shape>. Сеттеры состояния типизирует как React.Dispatch<React.SetStateAction<T>>. Тем же проходом чистит дочерние примитивы и убирает защитный код под состояния, которых не бывает.

Проверка идёт по пакету и по каждому потребителю: в монорепозитории автор советует bun --bun run typecheck --filter <package>. Сторис и тесты после сужения обычно падают, и починить их нужно реалистичными хендлерами, а не возвратом ?. Для запуска в CI есть шаблон ответа в references/response-template.md, он же становится телом PR.

Какие задачи решает

  • убрать опциональные колбэки у пунктов меню, которые отрисованы всегда
  • вывести тип аргумента из существующей функции вместо ручного дубля
  • заменить focusedItem?: T на обязательный focusedItem: T | null
  • вычистить fallback-логику, оставшуюся от широких типов
  • починить упавшие сторис через общий хелпер, не ослабляя пропсы

Примеры запросов агенту

  • Сузь пропсы `UserRow` до живых вызовов: найди все места использования вне тестов и убери опциональные хендлеры.
  • Посмотри, вызывает ли живой код `onArchive` в `ArchiveMenu`, и если да — сделай его обязательным.
  • Прогони typecheck по пакету и по всем потребителям после того, как сузишь пропсы `Dialog`.

Как установить narrow-react-prop-types

1Через Skills CLI (Vercel)

npx skills add humanlayer/skills --skill narrow-react-prop-types -a claude-code

2Вручную: положить файлы

~/.claude/skills/narrow-react-prop-types/SKILL.md

Папка скилла целиком; для одного проекта — .claude/skills/narrow-react-prop-types/

Из того же набора6

Весь набор →
show-me humanlayer Объясняет код и архитектуру через схемы Mermaid, деревья вызовов, diff и HTML-файлы. Пригодится, когда нужно быстро увидеть логику или структуру вместо чтения полотен текста. Claude Code CX Codex Cursor +1 32 300установок visual-pr humanlayer Скилл автоматизирует описание pull request: читает дифф, собирает контекст и оформляет PR по шаблону так, чтобы ревьюеру было понятно, зачем нужна перемена и как она устроена. Claude Code CX Codex Cursor +1 3 000установок improve-claude-md humanlayer Переписывает файл CLAUDE.md с помощью блоков <important if="условие">. Это заставляет Claude Code точнее следовать правилам и не отбрасывать важные инструкции проекта. Claude Code CX Codex Cursor +1 2 500установок design-control-loop humanlayer Скилл проводит интервью и вместе с вами проектирует агентскую петлю контроля: уставка, датчик, контроллер, актуатор. Потом собирает её прямо в вашем репозитории. Claude Code CX Codex Cursor +1 1 500установок build-iterated-agentic-loop humanlayer Помогает превратить повторяющуюся задачу для агента в скилл внутри репозитория и workflow GitHub Actions, который запускает кодинг-агента по расписанию, вручную или и так, и так. Claude Code CX Codex Cursor +1 1 400установок

Похожие

migrate-nativewind-to-uniwind uni-stack Скилл автоматизирует переход React Native проекта с NativeWind на Uniwind. Он обновляет конфиг, удаляет старые пакеты, перестраивает CSS и обрабатывает все breaking changes. Claude Code CX Codex Cursor +1 2 000установок react-router TanStack Скилл для агента по @tanstack/react-router: справочник хуков и компонентов плюс сборка файлового роутинга на Vite от установки до routeTree.gen. Claude Code CX Codex Cursor +1 546установок wpds WordPress Скилл подтягивает документацию WordPress Design System через MCP-сервер, чтобы агент собирал интерфейс на настоящих компонентах и токенах, а не по памяти. Claude Code CX Codex Cursor +1 4 000установок tanstack-query-best-practices DeckardGer Свод правил TanStack Query для React: ключи запросов, кеш, мутации, SSR. Подключается к Claude Code, Codex, Cursor и Copilot — чтобы загрузка данных в проекте шла по одной схеме. Claude Code CX Codex Cursor +1 12 800установок senior-frontend Alireza Rezvani Скилл помогает создавать React-компоненты, запускать проекты Next.js и проверять размер бандла. Пригодится при разработке интерфейса, аудите кода и настройке доступности. Claude Code 1 630установок generate Alireza Rezvani Скилл generate пишет тесты Playwright по пользовательской истории, URL, имени компонента или описанию фичи. Пригодится, когда надо быстро закрыть e2e-сценарий, а не писать его руками. Claude Code 1 624установок frontend-design официальный anthropics Скилл задаёт осмысленное визуальное направление для новых интерфейсов и редизайна. Подойдёт, когда стандартный шаблонный UI не устраивает. Claude Code Claude.ai 1 025 790установок design-taste-frontend Leonxlnx Скилл задаёт арт-дирекцию для публичных страниц и рабочих экранов, а затем проверяет результат в браузере по скриншотам. Нужен, когда интерфейс выглядит шаблонным или недоработанным. Claude Code CX Codex Cursor +1 673 100установок

Вопросы о narrow-react-prop-types

Как установить narrow-react-prop-types в Claude Code?

Выполните npx skills add humanlayer/skills --skill narrow-react-prop-types -a claude-code. Скилл окажется в ~/.claude/skills/narrow-react-prop-types/SKILL.md.

Что делает narrow-react-prop-types?

Сужает экспортируемый тип пропсов до состояний, которые встречаются в живом коде, и убирает из компонента защиту под состояния, которых там нет.

Скилл сломает мои сторис и тесты?

Скорее всего да. Правки вносятся в служебный код: сторис и тесты получают реалистичные хендлеры, а не возвращённый знак ? на пропсе.

Исходный текст

SKILL.md · MIT
---
name: narrow-react-prop-types
description: narrow React component prop types to match live code paths
---

# 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

For an example recurring GitHub Actions workflow that runs this skill through CodeLayer, see `references/agent-narrow-component-props.yml`. Its example agent memory file is `references/narrow-component-props-memory.md`. For CI agent response formatting, see `references/response-template.md`.

### 1. Identify the suspect component

Look for components with these signals:

- Large props interfaces with many optional fields.
- Optional callback calls such as `onSelect?.(...)` or `onArchive?.(...)`.
- Fallback state handling such as `items ?? []`, `count ?? 0`, or `handler && ...` 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:

```ts
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 broad, tighten those internal props too. Replace optional calls like this:

```ts
onRename?.(id, name)
```

with required calls:

```ts
onRename(id, name)
```

### 7. Remove fallback logic for unsupported states

Once props are required, remove defensive fallbacks that only existed for widened types.

Examples:

```ts
new Set(expandedIds ?? defaultExpandedIds ?? [])
```

should become:

```ts
new Set(expandedIds)
```

```ts
items && items.length > 0
```

should become:

```ts
items.length > 0
```

### 8. Update all variants that share the prop type

If multiple components share the broad prop type, update them together so they all enforce the same live-code-path contract.

### 9. Let tests and stories adapt to live code

If a story or test breaks after narrowing props, fix it by providing realistic handlers and state. Do not make live-code-path props optional again to reduce test setup.

If the story/test setup feels verbose, create a test helper or fixture that satisfies the strict live-code-path contract. Keep the helper in support code; do not weaken the component API.

### 10. Validate the change

Run package-level typechecks for the changed package and each live app/package that consumes the changed component.

Use repository-specific validation commands when available. In this monorepo, prefer:

```bash
bun --bun run typecheck --filter <package>
```

### 11. Format the response

When running as a CI agent, format your final response according to `references/response-template.md`. This response becomes the PR body.

Include:
- Summary of how many components were narrowed
- Table of changes with rationale
- Live call sites that justify each narrowing
- Support code (stories/tests) that needed updating
- Validation results
- Risk assessment

## Review Checklist

- The changed prop type was derived from non-test, non-Storybook call sites.
- Optional callbacks are removed for always-rendered interactions.
- Rendered menu items and buttons cannot be inert because of missing handlers.
- Removed props are not used by live code paths.
- Nullability is preserved only for real states, such as no current focus.
- Types are derived or extracted where possible rather than manually duplicated.
- `useState<T>(...)` is used where inference would otherwise widen or obscure the intended state.
- Shared variants compile against the same narrowed contract.
- Typecheck passes for the shared package and consuming live app/package.

## Anti-Patterns to Avoid

- Making callbacks optional so stories can omit them.
- Rendering a menu item that calls `onAction?.(...)`.
- Adding `default*` props for Storybook when live code is controlled.
- Using `?? []` or `?? 0` to hide missing required live state.
- Accepting multiple API shapes when live code only uses one.
- Treating pure components as mock components with relaxed contracts.

© humanlayer · MIT · humanlayer/skills

Смотрите также

Спонсоры проекта

Компании, которые помогают держать аналитику открытой