typescript-react-patterns — скилл для Claude Code: типизация React
Скилл с 33 правилами типизации React на TypeScript: пропсы, хуки, события, refs, дженерики и контекст. Пригодится, когда агент пишет компоненты и лезет в типы.
npx skills add AsyrafHussin/agent-skills --skill typescript-react-patterns -a claude-codeЧто делает typescript-react-patterns
Скилл разбит на 7 категорий по приоритету. Критичные — типизация компонентов и хуков, дальше идут события, refs, дженерики, контекст и утилитарные типы. У каждого правила свой префикс (comp-, hook-, event-, ref-, generic-, ctx-, util-) и отдельный файл в rules/, например rules/comp-props-interface.md или rules/hook-usestate.md.
Внутри есть готовые примеры: интерфейс пропсов кнопки с юнионом вариантов, типизированный контекст с проверкой на null и дженерик-компонент списка. Агент берёт эти шаблоны, когда вы просите написать компонент или починить ошибку типов. Полный свод правил лежит в AGENTS.md.
Скилл ставится через npx skills add и раскладывается в папку платформы — для Claude это ~/.claude/skills/typescript-react-patterns/SKILL.md. Ничего кроме самого скилла для работы не нужно. Если в проекте уже есть свои правила типизации, они будут спорить с этими 33 правилами: агент потянет шаблоны из скилла, и стиль кода может разъехаться.
Какие задачи решает
- типизировать пропсы компонента без
any - починить ошибку TypeScript в хуке
- описать обработчик события с нужным типом
- связать ref с конкретным HTML-элементом
- сделать дженерик-компонент списка или таблицы
Примеры запросов агенту
- напиши типизированный компонент Button с вариантами через юнион
- исправь ошибку типов в кастомном хуке useAuth
- сделай дженерик-компонент List с renderItem и keyExtractor
Как установить typescript-react-patterns
1Через Skills CLI (Vercel)
npx skills add AsyrafHussin/agent-skills --skill typescript-react-patterns -a claude-code2Вручную: положить файлы
~/.claude/skills/typescript-react-patterns/SKILL.mdПапка скилла целиком; для одного проекта — .claude/skills/typescript-react-patterns/
1Через Skills CLI (Vercel)
npx skills add AsyrafHussin/agent-skills --skill typescript-react-patterns -a codex2Вручную: положить файлы
.agents/skills/typescript-react-patterns/SKILL.mdДля всех проектов — ~/.agents/skills/
1Через Skills CLI (Vercel)
npx skills add AsyrafHussin/agent-skills --skill typescript-react-patterns -a cursor2Вручную: положить файлы
.cursor/skills/typescript-react-patterns/SKILL.mdCursor читает и .agents/skills/, и .claude/skills/
1GitHub CLI
gh skill install AsyrafHussin/agent-skills typescript-react-patterns2Вручную: положить файлы
.github/skills/typescript-react-patterns/SKILL.md1Через Skills CLI (Vercel)
npx skills add AsyrafHussin/agent-skills --skill typescript-react-patterns -a gemini-cli2Командой платформы
gemini skills install https://github.com/AsyrafHussin/agent-skills --path skills/typescript-react-patternsВручную: положить файлы
.devin/skills/typescript-react-patterns/SKILL.mdСтарый путь .windsurf/skills/ тоже читается
Через Skills CLI (Vercel)
npx skills add AsyrafHussin/agent-skills --skill typescript-react-patterns -a opencodeClaude.ai
Упакуйте папку в zip и загрузите в Settings → Capabilities → Skills
По шагам, с командами для каждой платформы: Как установить скилл в Claude Code: пять способов
Вопросы о typescript-react-patterns
Как установить typescript-react-patterns в Claude?
Выполните npx skills add AsyrafHussin/agent-skills --skill typescript-react-patterns -a claude-code. Скилл появится в ~/.claude/skills/typescript-react-patterns/SKILL.md.
Что делает typescript-react-patterns?
Даёт агенту 33 правила типизации React на TypeScript: пропсы, хуки, события, refs, дженерики, контекст и утилитарные типы. Агент подставляет их, когда пишет компоненты или разбирает ошибки типов.
Чем этот скилл отличается от обычных подсказок по TypeScript?
Правила разложены по файлам в rules/ с префиксами по категориям, а полный свод собран в AGENTS.md. Агент читает нужный файл под задачу, а не весь гайд целиком.
Исходный текст
SKILL.md · MIT
---
name: typescript-react-patterns
description: TypeScript best practices for React development. Use when writing typed React components, hooks, events, refs, or generic components. Triggers on tasks involving TypeScript errors, type definitions, props typing, or type-safe React patterns.
license: MIT
metadata:
author: agent-skills
version: "2.0.0"
---
# TypeScript React Patterns
Type-safe React with TypeScript. Contains 33 rules across 7 categories covering component typing, hooks, event handling, refs, generics, context, and utility types.
## Metadata
- **Version:** 2.0.0
- **Rule Count:** 33 rules across 7 categories
- **License:** MIT
## When to Apply
Reference these guidelines when:
- Typing React component props
- Creating custom hooks with TypeScript
- Handling events with proper types
- Working with refs (DOM, mutable, imperative)
- Building generic, reusable components
- Setting up typed Context providers
- Fixing TypeScript errors in React code
## Rule Categories by Priority
| Priority | Category | Impact | Prefix |
|----------|----------|--------|--------|
| 1 | Component Typing | CRITICAL | `comp-` |
| 2 | Hook Typing | CRITICAL | `hook-` |
| 3 | Event Handling | HIGH | `event-` |
| 4 | Ref Typing | HIGH | `ref-` |
| 5 | Generic Components | MEDIUM | `generic-` |
| 6 | Context & State | MEDIUM | `ctx-` |
| 7 | Utility Types | LOW | `util-` |
## Quick Reference
### 1. Component Typing (CRITICAL)
- `comp-props-interface` - Use interface for props, type for unions
- `comp-children-types` - Correct children typing (ReactNode, ReactElement)
- `comp-default-props` - Default props with destructuring defaults
- `comp-forward-ref` - Typing forwardRef components
- `comp-polymorphic` - Polymorphic "as" prop typing
- `comp-fc-vs-function` - Function declaration vs React.FC
- `comp-display-name` - Display names for debugging
- `comp-rest-props` - Spreading rest props with proper types
### 2. Hook Typing (CRITICAL)
- `hook-usestate` - useState with proper generic types
- `hook-useref` - useRef for DOM elements and mutable values
- `hook-use-reducer` - useReducer with discriminated union actions
- `hook-use-callback` - useCallback with typed parameters
- `hook-use-memo` - useMemo with typed return values
- `hook-use-context` - useContext with null checking
- `hook-custom-hooks` - Custom hook return types
- `hook-generic-hooks` - Generic custom hooks
### 3. Event Handling (HIGH)
- `event-handler-types` - Event handler type patterns
- `event-click-handler` - Click event typing
- `event-form` - Form event handling (submit, change, select)
- `event-keyboard` - Keyboard event types
### 4. Ref Typing (HIGH)
- `ref-dom-elements` - useRef with specific HTML element types
- `ref-callback` - Callback ref pattern for DOM measurement
- `ref-imperative-handle` - useImperativeHandle typing
### 5. Generic Components (MEDIUM)
- `generic-list` - Generic list components
- `generic-select` - Generic select/dropdown
- `generic-table` - Generic table with typed columns
- `generic-constraints` - Generic constraints with extends
### 6. Context & State (MEDIUM)
- `ctx-create` - Creating typed context
- `ctx-provider` - Provider pattern with null check hook
- `ctx-reducer` - Context with useReducer
### 7. Utility Types (LOW)
- `util-component-props` - ComponentPropsWithoutRef for HTML props
- `util-pick-omit` - Pick, Omit, Partial for prop derivation
- `util-discriminated-unions` - Discriminated unions for state machines
## Essential Patterns
### Component Props
```tsx
interface ButtonProps {
variant: 'primary' | 'secondary' | 'danger'
size?: 'sm' | 'md' | 'lg'
children: React.ReactNode
onClick?: () => void
}
function Button({ variant, size = 'md', children, onClick }: ButtonProps) {
return (
<button className={`btn-${variant} btn-${size}`} onClick={onClick}>
{children}
</button>
)
}
```
### Typed Context with Null Check
```tsx
interface AuthContextType {
user: User | null
login: (credentials: Credentials) => Promise<void>
logout: () => void
}
const AuthContext = createContext<AuthContextType | null>(null)
function useAuth() {
const context = useContext(AuthContext)
if (!context) throw new Error('useAuth must be used within AuthProvider')
return context
}
```
### Generic Component
```tsx
interface ListProps<T> {
items: T[]
renderItem: (item: T) => React.ReactNode
keyExtractor: (item: T) => string
}
function List<T>({ items, renderItem, keyExtractor }: ListProps<T>) {
return <ul>{items.map(item => <li key={keyExtractor(item)}>{renderItem(item)}</li>)}</ul>
}
```
## How to Use
Read individual rule files for detailed explanations:
```
rules/comp-props-interface.md
rules/hook-usestate.md
rules/event-form.md
rules/ref-dom-elements.md
rules/util-discriminated-unions.md
```
## References
- [React TypeScript Cheatsheet](https://react-typescript-cheatsheet.netlify.app)
- [React + TypeScript Guide](https://react.dev/learn/typescript)
- [TypeScript Handbook](https://www.typescriptlang.org/docs/handbook/)
## Full Compiled Document
For the complete guide with all rules expanded: `AGENTS.md`
© agent-skills · MIT · AsyrafHussin/agent-skills