본문으로 건너뛰기
Skillpedia
웹사이트 및 UI (프런트엔드)13k · #11388

narrow-react-prop-types

하는 일

이 스킬은 스토리나 테스트 데이터만을 위해 있는 선택적 프롭을 제거하도록 AI 에이전트를 안내합니다. 엄격하고 정확한 컴포넌트 타입을 원하는 React 개발자를 위한 스킬입니다.

사용하는 경우

  • ✓스토리나 테스트를 지원하려고 컴포넌트 프롭이 넓어지고 선택적으로 바뀌었을 때.
  • ✓실제 앱에서 쓰지 않는 상태를 없애고 싶을 때.
  • ✓라이브 코드에서 파생된 타입을 얻고 싶은 React 타입 리팩터링이 있는 경우.

스킬 링크

https://github.com/humanlayer/humanlayer/blob/main/.claude/skills/narrow-react-prop-types/SKILL.md

복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.

사용 방법

가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.

바로 붙여넣을 수 있는 메시지

Use this skill to help me: https://github.com/humanlayer/humanlayer/blob/main/.claude/skills/narrow-react-prop-types/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
AI가 이런 스킬을 알아서 찾아 쓰길 원하시나요?무료 Skillpedia MCP를 설치하세요. 한 줄이면 작업마다 스킬 15,000+개 중에서 검색합니다.1분 만에 설치 →

AI에게 요청하는 예시

“이 React 카드 컴포넌트에는 선택적 프롭이 너무 많아요. 실제 앱이 쓰는 것으로 타입을 좁혀 주세요.”

매주 새 스킬 5개. 읽는 데 1분.

작동 방식

에이전트는 타입을 바꾸기 전에 실제 테스트가 아닌 호출 위치를 먼저 찾습니다. 그다음 타입을 그 호출 위치에 맞추고, 테스트와 스토리 코드를 더 엄격한 타입에 맞게 업데이트합니다.

기술 내용 (원본 SKILL.md)

작성자의 영어 원문을 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?.(...) 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:

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

자주 묻는 질문

테스트가 깨지나요?

테스트와 스토리를 업데이트해야 할 수 있으며, 스킬은 타입을 느슨하게 하지 않고 더 엄격한 타입에 맞춥니다.

타입을 바꾸기 전에 실제 앱을 확인하나요?

네. 변경하기 전에 실제 테스트가 아닌 호출 위치를 찾습니다.

일부 프롭은 선택적으로 남을 수 있나요?

네. 다만 실제 호출 위치가 그 값을 제공하지 않고 타당한 이유가 있을 때만입니다.

상세 정보

작성자의 원본 설명

narrow React component prop types to match live code paths

repo: humanlayer/humanlayer

인기도

GitHub 스타
13k
순위
#11388
라이선스
Apache-2.0
업데이트
2026. 10. 31.

이 스킬이 유용한가요?

0

로그인 투표하려면 로그인하세요.

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬