narrow-react-prop-types
Skill này làm gì
Skill hướng dẫn agent AI bỏ các prop tùy chọn chỉ tồn tại để phục vụ dữ liệu test hoặc story. Skill dành cho lập trình viên React muốn kiểu component chặt và chính xác.
Khi nào nên dùng
- ✓Khi prop của một component đã rộng và trở nên tùy chọn chỉ để hỗ trợ story hoặc test.
- ✓Khi bạn muốn bỏ các trạng thái mà ứng dụng thật không bao giờ dùng.
- ✓Khi bạn đang refactor kiểu React và muốn chúng được suy ra từ code đang chạy.
Liên kết skill
https://github.com/humanlayer/humanlayer/blob/main/.claude/skills/narrow-react-prop-types/SKILL.mdSao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.
Cách dùng
Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.
Tin nhắn có sẵn để dán
Dành cho Claude Code, Codex hoặc Cursor: chạy lệnh trong thư mục dự án của bạn và skill sẽ được cài đặt.
Tải tệp SKILL.md về và thả vào thư mục skill của agent.
Ví dụ cách nhờ AI
“Component card React này có quá nhiều prop tùy chọn. Hãy thu hẹp kiểu về đúng những gì ứng dụng thật sử dụng.”
5 skill mới mỗi tuần. Đọc chỉ 1 phút.
Cách hoạt động
Agent tìm các nơi gọi thật ngoài code test trước, rồi làm kiểu khớp với chúng. Sau đó code test và story được cập nhật để phù hợp với kiểu chặt hơn.
Nội dung kỹ thuật (SKILL.md gốc)
Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.
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
Câu hỏi thường gặp
Nó có làm hỏng test của tôi không?
Test và story có thể cần cập nhật, vì skill điều chỉnh chúng theo kiểu chặt hơn thay vì làm yếu kiểu.
Nó có kiểm tra ứng dụng thật trước không?
Có. Nó tìm các nơi gọi thật trước khi thay đổi bất kỳ kiểu nào.
Có prop nào vẫn có thể tùy chọn không?
Có, nhưng chỉ khi không có nơi gọi thật nào cung cấp nó và có lý do chính đáng.
Chi tiết
Mô tả gốc của tác giả
narrow React component prop types to match live code paths
repo: humanlayer/humanlayer
Độ phổ biến
- Sao GitHub
- 13k
- Vị trí xếp hạng
- #11388
- Giấy phép
- Apache-2.0
- Cập nhật
- 31/10/2026
Bình luận
- …
Thêm skill từ kho mã này
asd-ste100
13kDạy agent của bạn viết lại tiếng Anh khó hiểu thành câu ngắn, mỗi câu một nghĩa, dễ đọc đối với con người và phần mềm khác.
better-github-skill
13kGiúp agent của bạn kiểm tra trạng thái pull request, đọc bình luận review và tìm lý do bản build CI thất bại, bằng các script GitHub có sẵn.
calldiff
13kGiúp agent của bạn so sánh chuỗi lời gọi hàm trong một codebase giữa hai phiên bản git, để review code thấy hành vi nào đã thay đổi.
chrome-devtools-cli
13kCho phép agent của bạn điều khiển Chrome từ terminal để mở trang, nhấp, điền biểu mẫu và chụp snapshot trang cho tự động hóa và kiểm thử trình duyệt.
Skill tương tự
angular-developer
280kGiúp agent của bạn viết code Angular và tư vấn cấu trúc dự án, hữu ích khi bắt đầu dự án mới hoặc cải thiện hiệu suất.
frontend-a11y
280kGiúp agent của bạn làm cho giao diện web dễ tiếp cận với mọi người. Đảm bảo website và ứng dụng hoạt động tốt với trình đọc màn hình và điều hướng bằng bàn phím.
frontend-patterns
280kGiúp agent của bạn áp dụng các mẫu hiện đại trong phát triển frontend. Tối ưu hiệu năng, quản lý trạng thái và tuân theo thực hành tốt nhất với React và Next.js.