मुख्य सामग्री पर जाएँ
Skillpedia
वेबसाइट और UI (frontend)13k · #11388

narrow-react-prop-types

यह क्या करती है

यह AI एजेंट को उन वैकल्पिक props को हटाने का मार्गदर्शन देती है जो केवल टेस्ट या स्टोरी डेटा के लिए हों। यह उन React डेवलपर्स के लिए है जो सख्त और सटीक कॉम्पोनेंट टाइप चाहते हैं।

कब इस्तेमाल करें

  • ✓जब किसी कॉम्पोनेंट के props केवल स्टोरी या टेस्ट के लिए चौड़े और वैकल्पिक हो गए हों।
  • ✓जब आप ऐसी स्थितियाँ हटाना चाहते हैं जो असली ऐप कभी इस्तेमाल नहीं करता।
  • ✓जब आप React टाइप को रीफ़ैक्टर कर रहे हैं और चाहते हैं कि वे लाइव कोड से निकलें।

Skill का लिंक

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

इसे कॉपी करके अपने AI (Claude, ChatGPT या Cursor) में पेस्ट करें और निर्देशों का पालन करने को कहें।

कैसे इस्तेमाल करें

सबसे आसान तरीका: मैसेज कॉपी करके अपने AI में पेस्ट करें। वह skill पढ़कर निर्देशों का पालन करेगा।

पेस्ट करने के लिए तैयार मैसेज

इस skill से मेरी मदद करो: https://github.com/humanlayer/humanlayer/blob/main/.claude/skills/narrow-react-prop-types/SKILL.md इस लिंक की SKILL.md फ़ाइल पढ़ो और मेरे काम में उसके निर्देशों का पालन करो।
क्या आप चाहते हैं कि आपका AI ऐसी skills खुद ढूँढे?मुफ़्त Skillpedia MCP इंस्टॉल करें: बस एक लाइन, और हर काम से पहले यह 15,000+ skills में खोजता है।1 मिनट में इंस्टॉल करें →

AI से क्या माँगें: उदाहरण

“इस React कार्ड कॉम्पोनेंट में बहुत सारे वैकल्पिक props हैं। टाइप को उतना ही सीमित कीजिए जितना असली ऐप इस्तेमाल करता है।”

हर हफ़्ते 5 नई skills, 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

अक्सर पूछे जाने वाले सवाल

क्या इससे मेरे टेस्ट टूटेंगे?

टेस्ट और स्टोरी को अपडेट करना पड़ सकता है, क्योंकि स्किल टाइप को ढीला करने के बजाय उन्हें सख्त टाइप के अनुरूप ढालती है।

क्या यह पहले असली ऐप जाँचती है?

हाँ। किसी भी टाइप को बदलने से पहले यह असली गैर-टेस्ट कॉल साइट खोजती है।

क्या कुछ props वैकल्पिक रह सकते हैं?

हाँ, लेकिन केवल तब जब कोई असली कॉल साइट उन्हें न दे और उसका कोई ठोस कारण हो।

जानकारी

लेखक का मूल विवरण

narrow React component prop types to match live code paths

repo: humanlayer/humanlayer

लोकप्रियता

GitHub स्टार
13k
रैंकिंग में स्थान
#11388
लाइसेंस
Apache-2.0
अपडेट की गई
31/10/2026

क्या यह skill काम की है?

0

लॉग इन करें वोट करने के लिए।

कमेंट

  • …

इस repository की और skills

asd-ste100

13k

उलझे हुए अंग्रेज़ी टेक्स्ट को छोटे, एक-अर्थ वाले वाक्यों में बदलना सिखाती है, जो लोगों और दूसरे सॉफ़्टवेयर दोनों के लिए पढ़ने में आसान हों।

लेखन और डॉक्यूमेंटलेखन

better-github-skill

13k

तैयार GitHub स्क्रिप्ट से pull request की स्थिति जाँचने, उसकी समीक्षा टिप्पणियाँ पढ़ने, और CI बिल्ड क्यों विफल हुआ यह पता करने में आपके एजेंट की मदद करती है।

कोडिंगडिप्लॉय और क्लाउड (DevOps)

calldiff

13k

कोड समीक्षा में बदलाव का असर देखने के लिए, दो git संस्करणों के बीच कोड में फ़ंक्शन कॉल की श्रृंखलाओं की तुलना करने में मदद करती है।

कोडिंगसामान्य कोडिंग

chrome-devtools-cli

13k

आपके एजेंट को टर्मिनल से Chrome चलाने देती है, ताकि वह पेज खोल सके, क्लिक कर सके, फ़ॉर्म भर सके और ब्राउज़र ऑटोमेशन व टेस्टिंग के लिए पेज का स्नैपशॉट ले सके।

कोडिंगटेस्टिंग

मिलती-जुलती skills